How to resolve missing module Tweepy on Heroku? - flask

I'm running at python script to automatically tweet updates from my website running on Heroku. The tweepy script is executed every hour. The script works in the local environment but won't execute on Heroku.
The error log is below:
2020-05-02T12:32:41.805232+00:00 app[scheduler.6938]: File "/app/app/main/twitter.py", line 1, in <module>
2020-05-02T12:32:41.805363+00:00 app[scheduler.6938]: import tweepy
2020-05-02T12:32:41.805363+00:00 app[scheduler.6938]: File "/app/.heroku/python/lib/python3.6/site-packages/tweepy/__init__.py", line 12, in <module>
2020-05-02T12:32:41.805500+00:00 app[scheduler.6938]: from tweepy.api import API
2020-05-02T12:32:41.805503+00:00 app[scheduler.6938]: File "/app/.heroku/python/lib/python3.6/site-packages/tweepy/api.py", line 10, in <module>
2020-05-02T12:32:41.805645+00:00 app[scheduler.6938]: from tweepy.binder import bind_api
2020-05-02T12:32:41.805647+00:00 app[scheduler.6938]: File "/app/.heroku/python/lib/python3.6/site-packages/tweepy/binder.py", line 10, in <module>
2020-05-02T12:32:41.805772+00:00 app[scheduler.6938]: import requests
2020-05-02T12:32:41.805832+00:00 app[scheduler.6938]: File "/app/.heroku/python/lib/python3.6/site-packages/requests/__init__.py", line 43, in <module>
2020-05-02T12:32:41.805968+00:00 app[scheduler.6938]: import urllib3
2020-05-02T12:32:41.805971+00:00 app[scheduler.6938]: File "/app/.heroku/python/lib/python3.6/site-packages/urllib3/__init__.py", line 7, in <module>
2020-05-02T12:32:41.806110+00:00 app[scheduler.6938]: from .connectionpool import HTTPConnectionPool, HTTPSConnectionPool, connection_from_url
2020-05-02T12:32:41.806114+00:00 app[scheduler.6938]: File "/app/.heroku/python/lib/python3.6/site-packages/urllib3/connectionpool.py", line 11, in <module>
2020-05-02T12:32:41.806230+00:00 app[scheduler.6938]: from .exceptions import (
2020-05-02T12:32:41.806266+00:00 app[scheduler.6938]: File "/app/.heroku/python/lib/python3.6/site-packages/urllib3/exceptions.py", line 2, in <module>
2020-05-02T12:32:41.806407+00:00 app[scheduler.6938]: from .packages.six.moves.http_client import IncompleteRead as httplib_IncompleteRead
2020-05-02T12:32:41.806411+00:00 app[scheduler.6938]: File "/app/.heroku/python/lib/python3.6/site-packages/urllib3/packages/six.py", line 199, in load_module
2020-05-02T12:32:41.806614+00:00 app[scheduler.6938]: mod = mod._resolve()
2020-05-02T12:32:41.806618+00:00 app[scheduler.6938]: File "/app/.heroku/python/lib/python3.6/site-packages/urllib3/packages/six.py", line 113, in _resolve
2020-05-02T12:32:41.806805+00:00 app[scheduler.6938]: return _import_module(self.mod)
2020-05-02T12:32:41.806809+00:00 app[scheduler.6938]: File "/app/.heroku/python/lib/python3.6/site-packages/urllib3/packages/six.py", line 82, in _import_module
2020-05-02T12:32:41.806954+00:00 app[scheduler.6938]: __import__(name)
2020-05-02T12:32:41.806957+00:00 app[scheduler.6938]: File "/app/.heroku/python/lib/python3.6/http/client.py", line 71, in <module>
2020-05-02T12:32:41.807124+00:00 app[scheduler.6938]: import email.parser
2020-05-02T12:32:41.807128+00:00 app[scheduler.6938]: File "/app/app/main/email.py", line 1, in <module>
2020-05-02T12:32:41.807244+00:00 app[scheduler.6938]: from flask import current_app
2020-05-02T12:32:41.807245+00:00 app[scheduler.6938]: File "/app/.heroku/python/lib/python3.6/site-packages/flask/__init__.py", line 19, in <module>
2020-05-02T12:32:41.807371+00:00 app[scheduler.6938]: from . import json
2020-05-02T12:32:41.807375+00:00 app[scheduler.6938]: File "/app/.heroku/python/lib/python3.6/site-packages/flask/json/__init__.py", line 17, in <module>
2020-05-02T12:32:41.807504+00:00 app[scheduler.6938]: from werkzeug.http import http_date
2020-05-02T12:32:41.807508+00:00 app[scheduler.6938]: File "/app/.heroku/python/lib/python3.6/site-packages/werkzeug/__init__.py", line 218, in <module>
2020-05-02T12:32:41.807677+00:00 app[scheduler.6938]: from .serving import run_simple
2020-05-02T12:32:41.807681+00:00 app[scheduler.6938]: File "/app/.heroku/python/lib/python3.6/site-packages/werkzeug/serving.py", line 59, in <module>
2020-05-02T12:32:41.807876+00:00 app[scheduler.6938]: import SocketServer as socketserver
2020-05-02T12:32:41.807879+00:00 app[scheduler.6938]: ModuleNotFoundError: No module named 'SocketServer'

Import Error is with SocketServer not tweepy.
Import it like this
import socketserver
Yes, it's socketserver only by default not SocketServer.
Reference

Related

AttributeError: 'EntryPoints' object has no attribute 'get' with superset

I am installing superset and at the level of superset db upgrade I got an error saying: AttributeError: 'EntryPoints' object has no attribute 'get'
Error:
python datavisual\Scripts\superset db upgrade
Traceback (most recent call last):
File "datavisual\Scripts\superset", line 18, in <module>
from superset.cli import superset
File "C:\Users\user\Desktop\superset\datavisual\lib\site-packages\superset\__init__.py", line 21, in <module>
from superset.app import create_app
File "C:\Users\user\Desktop\superset\datavisual\lib\site-packages\superset\app.py", line 29, in <module>
from superset.extensions import (
File "C:\Users\user\Desktop\superset\datavisual\lib\site-packages\superset\extensions.py", line 126, in <module>
celery_app = celery.Celery()
File "C:\Users\user\Desktop\superset\datavisual\lib\site-packages\celery\local.py", line 470, in __getattr__
[name])
File "C:\Users\user\Desktop\superset\datavisual\lib\site-packages\celery\app\__init__.py", line 2, in <module>
from celery import _state
File "C:\Users\user\Desktop\superset\datavisual\lib\site-packages\celery\_state.py", line 15, in <module>
from celery.utils.threads import LocalStack
File "C:\Users\user\Desktop\superset\datavisual\lib\site-packages\celery\utils\__init__.py", line 16, in <module>
from .nodenames import nodename, nodesplit, worker_direct
File "C:\Users\user\Desktop\superset\datavisual\lib\site-packages\celery\utils\nodenames.py", line 6, in <module>
from kombu.entity import Exchange, Queue
File "C:\Users\user\Desktop\superset\datavisual\lib\site-packages\kombu\entity.py", line 7, in <module>
from .serialization import prepare_accept_content
File "C:\Users\user\Desktop\superset\datavisual\lib\site-packages\kombu\serialization.py", line 440, in <module>
for ep, args in entrypoints('kombu.serializers'): # pragma: no cover
File "C:\Users\user\Desktop\superset\datavisual\lib\site-packages\kombu\utils\compat.py", line 82, in entrypoints
for ep in importlib_metadata.entry_points().get(namespace, [])
AttributeError: 'EntryPoints' object has no attribute 'get'

Error loading patching payloadfailed to run commands: exit status 156

I'm automating my EC2 instances with Patch Manager and I'm getting this error.
Error loading patching payloadfailed to run commands: exit status 156
The error output logs are these:
/usr/bin/python3
/usr/bin/apt-get
Reading package lists...
Building dependency tree...
Reading state information...
python3-apt is already the newest version (2.3.0ubuntu2).
0 upgraded, 0 newly installed, 0 to remove and 8 not upgraded.
Using python binary: 'python3'
Using Python Version: Python 3.10.4
/usr/bin/curl
/usr/bin/wget
05/29/2022 01:11:51 root [INFO]: Downloading payload from https://s3.dualstack.sa-east-1.amazonaws.com/aws-ssm-sa-east-1/patchbaselineoperations/linux/payloads/patch-baseline-operations-1.86.tar.gz
05/29/2022 01:11:52 root [INFO]: Attempting to import entrance file os_selector
05/29/2022 01:11:52 root [ERROR]: Error loading entrance module.
Traceback (most recent call last):
File "/var/log/amazon/ssm/patch-baseline-operations/common_startup_entrance.py", line 154, in execute
entrance_module = __import__(module_name)
File "/var/log/amazon/ssm/patch-baseline-operations/os_selector.py", line 11, in <module>
import common_os_selector_methods
File "/var/log/amazon/ssm/patch-baseline-operations/common_os_selector_methods.py", line 11, in <module>
from patch_common.baseline_override import load_baseline_override
File "/var/log/amazon/ssm/patch-baseline-operations/patch_common/baseline_override.py", line 6, in <module>
from patch_common.downloader import download_file, load_json_file, is_access_denied
File "/var/log/amazon/ssm/patch-baseline-operations/patch_common/downloader.py", line 1, in <module>
import boto3
File "/var/log/amazon/ssm/patch-baseline-operations/boto3/__init__.py", line 16, in <module>
from boto3.session import Session
File "/var/log/amazon/ssm/patch-baseline-operations/boto3/session.py", line 17, in <module>
import botocore.session
File "/var/log/amazon/ssm/patch-baseline-operations/botocore/session.py", line 29, in <module>
import botocore.configloader
File "/var/log/amazon/ssm/patch-baseline-operations/botocore/configloader.py", line 19, in <module>
from botocore.compat import six
File "/var/log/amazon/ssm/patch-baseline-operations/botocore/compat.py", line 25, in <module>
from botocore.exceptions import MD5UnavailableError
File "/var/log/amazon/ssm/patch-baseline-operations/botocore/exceptions.py", line 15, in <module>
from botocore.vendored import requests
File "/var/log/amazon/ssm/patch-baseline-operations/botocore/vendored/requests/__init__.py", line 58, in <module>
from . import utils
File "/var/log/amazon/ssm/patch-baseline-operations/botocore/vendored/requests/utils.py", line 26, in <module>
from .compat import parse_http_list as _parse_list_header
File "/var/log/amazon/ssm/patch-baseline-operations/botocore/vendored/requests/compat.py", line 7, in <module>
from .packages import chardet
File "/var/log/amazon/ssm/patch-baseline-operations/botocore/vendored/requests/packages/__init__.py", line 3, in <module>
from . import urllib3
File "/var/log/amazon/ssm/patch-baseline-operations/botocore/vendored/requests/packages/urllib3/__init__.py", line 10, in <module>
from .connectionpool import (
File "/var/log/amazon/ssm/patch-baseline-operations/botocore/vendored/requests/packages/urllib3/connectionpool.py", line 38, in <module>
from .response import HTTPResponse
File "/var/log/amazon/ssm/patch-baseline-operations/botocore/vendored/requests/packages/urllib3/response.py", line 9, in <module>
from ._collections import HTTPHeaderDict
File "/var/log/amazon/ssm/patch-baseline-operations/botocore/vendored/requests/packages/urllib3/_collections.py", line 1, in <module>
from collections import Mapping, MutableMapping
ImportError: cannot import name 'Mapping' from 'collections' (/usr/lib/python3.10/collections/__init__.py)
05/29/2022 01:11:52 root [ERROR]: cannot import name 'Mapping' from 'collections' (/usr/lib/python3.10/collections/__init__.py)
Traceback (most recent call last):
File "/var/log/amazon/ssm/patch-baseline-operations/common_startup_entrance.py", line 154, in execute
entrance_module = __import__(module_name)
File "/var/log/amazon/ssm/patch-baseline-operations/os_selector.py", line 11, in <module>
import common_os_selector_methods
File "/var/log/amazon/ssm/patch-baseline-operations/common_os_selector_methods.py", line 11, in <module>
from patch_common.baseline_override import load_baseline_override
File "/var/log/amazon/ssm/patch-baseline-operations/patch_common/baseline_override.py", line 6, in <module>
from patch_common.downloader import download_file, load_json_file, is_access_denied
File "/var/log/amazon/ssm/patch-baseline-operations/patch_common/downloader.py", line 1, in <module>
import boto3
File "/var/log/amazon/ssm/patch-baseline-operations/boto3/__init__.py", line 16, in <module>
from boto3.session import Session
File "/var/log/amazon/ssm/patch-baseline-operations/boto3/session.py", line 17, in <module>
import botocore.session
File "/var/log/amazon/ssm/patch-baseline-operations/botocore/session.py", line 29, in <module>
import botocore.configloader
File "/var/log/amazon/ssm/patch-baseline-operations/botocore/configloader.py", line 19, in <module>
from botocore.compat import six
File "/var/log/amazon/ssm/patch-baseline-operations/botocore/compat.py", line 25, in <module>
from botocore.exceptions import MD5UnavailableError
File "/var/log/amazon/ssm/patch-baseline-operations/botocore/exceptions.py", line 15, in <module>
from botocore.vendored import requests
File "/var/log/amazon/ssm/patch-baseline-operations/botocore/vendored/requests/__init__.py", line 58, in <module>
from . import utils
File "/var/log/amazon/ssm/patch-baseline-operations/botocore/vendored/requests/utils.py", line 26, in <module>
from .compat import parse_http_list as _parse_list_header
File "/var/log/amazon/ssm/patch-baseline-operations/botocore/vendored/requests/compat.py", line 7, in <module>
from .packages import chardet
File "/var/log/amazon/ssm/patch-baseline-operations/botocore/vendored/requests/packages/__init__.py", line 3, in <module>
from . import urllib3
File "/var/log/amazon/ssm/patch-baseline-operations/botocore/vendored/requests/packages/urllib3/__init__.py", line 10, in <module>
from .connectionpool import (
File "/var/log/amazon/ssm/patch-baseline-operations/botocore/vendored/requests/packages/urllib3/connectionpool.py", line 38, in <module>
from .response import HTTPResponse
File "/var/log/amazon/ssm/patch-baseline-operations/botocore/vendored/requests/packages/urllib3/response.py", line 9, in <module>
from ._collections import HTTPHeaderDict
File "/var/log/amazon/ssm/patch-baseline-operations/botocore/vendored/requests/packages/urllib3/_collections.py", line 1, in <module>
from collections import Mapping, MutableMapping
ImportError: cannot import name 'Mapping' from 'collections' (/usr/lib/python3.10/collections/__init__.py)
Does anyone have an idea what it could be?
What's the Ubuntu version being used here?
Looking at the Python version (Python 3.10.4) in the error logs, that target instance appears to be running Ubuntu 22.04, which is not yet supported by Patch Manager.
Below is the link for the supported operating systems in Patch Manager prerequisites documentation:
https://docs.aws.amazon.com/systems-manager/latest/userguide/patch-manager-prerequisites.html

my from sklearn.decomposition import PCA have an error

I tried using "from sklearn.decomposition import PCA" on windows python 2.7 to my program, but the result was an error and it said like this:
Traceback (most recent call last):
File "<pyshell#6>", line 1, in <module>
from sklearn.decomposition import PCA
File "C:\Python27\lib\site-packages\sklearn\decomposition\__init__.py", line 10, in <module>
from .kernel_pca import KernelPCA
File "C:\Python27\lib\site-packages\sklearn\decomposition\kernel_pca.py", line 14, in <module>
from ..preprocessing import KernelCenterer
File "C:\Python27\lib\site-packages\sklearn\preprocessing\__init__.py", line 8, in <module>
from .data import Binarizer
File "C:\Python27\lib\site-packages\sklearn\preprocessing\data.py", line 18, in <module>
from scipy import stats
File "C:\Python27\lib\site-packages\scipy\stats\__init__.py", line 343, in <module>
from .stats import *
File "C:\Python27\lib\site-packages\scipy\stats\stats.py", line 171, in <module>
from . import distributions
File "C:\Python27\lib\site-packages\scipy\stats\distributions.py", line 10, in <module>
from ._distn_infrastructure import (entropy, rv_discrete, rv_continuous,
File "C:\Python27\lib\site-packages\scipy\stats\_distn_infrastructure.py", line 16, in <module>
from scipy.misc import doccer
File "C:\Python27\lib\site-packages\scipy\misc\__init__.py", line 97, in <module>
from .pilutil import *
File "C:\Python27\lib\site-packages\scipy\misc\pilutil.py", line 21, in <module>
import Image
File "C:\Python27\lib\site-packages\PIL\Image.py", line 27, in <module>
from . import VERSION, PILLOW_VERSION, _plugins
ValueError: Attempted relative import in non-package
what's wrong with that? yesterday back then, I used that "from sklearn.decomposition import PCA" to my program and there's no problem whit that. help me please

tensorflow import error in python 2.7.6

I have installed tensor flow from tensorflow website. While trying to import tensor flow its showing following error
>>>import tensorflow as tf
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/dist-packages/tensorflow/__init__.py", line 24, in <module>
from tensorflow.python import *
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/__init__.py", line 75, in <module>
from tensorflow.core.framework.graph_pb2 import *
File "/usr/local/lib/python2.7/dist-packages/tensorflow/core/framework/graph_pb2.py", line 6, in <module>
from google.protobuf import descriptor as _descriptor
File "/usr/local/lib/python2.7/dist-packages/google/protobuf/__init__.py", line 37, in <module>
__import__('pkg_resources').declare_namespace(__name__)
File "/usr/local/lib/python2.7/dist-packages/pkg_resources/__init__.py", line 36, in <module>
import email.parser
File "/usr/lib/python2.7/email/parser.py", line 12, in <module>
from email.feedparser import FeedParser
File "/usr/lib/python2.7/email/feedparser.py", line 27, in <module>
from email import message
File "/usr/lib/python2.7/email/message.py", line 16, in <module>
import email.charset
File "/usr/lib/python2.7/email/charset.py", line 13, in <module>
import email.base64mime
File "/usr/lib/python2.7/email/base64mime.py", line 40, in <module>
from email.utils import fix_eols
File "/usr/lib/python2.7/email/utils.py", line 28, in <module>
import socket
File "/home/tamarind/socket.py", line 5, in <module>
This module provides socket operations and some related functions.
TypeError: 'module' object is not callable
I think its problem with socket please suggest. Please suggest.
It looks like /home/tamarind/socket.py is taking precedence over the python socket module. Just rename/remove that (or import TensorFlow from a different directory) and it should work. You may need to remove socket.pyc too.

ImportError: cannot import name _counter but _counter.pyd exists

I am encountering the below stacktrace when running import paramiko (this is in windows platform)
File "/usr/lib/python2.7/site-packages/paramiko/__init__.py", line 30, in <module>
from paramiko.transport import SecurityOptions, Transport
File "/usr/lib/python2.7/site-packages/paramiko/transport.py", line 50, in <module>
from paramiko.dsskey import DSSKey
File "/usr/lib/python2.7/site-packages/paramiko/dsskey.py", line 26, in <module>
from Crypto.PublicKey import DSA
File "/usr/lib/python2.7/site-packages/Crypto/PublicKey/DSA.py", line 89, in <module>
from Crypto import Random
File "/usr/lib/python2.7/site-packages/Crypto/Random/__init__.py", line 29, in <module>
from Crypto.Random import _UserFriendlyRNG
File "/usr/lib/python2.7/site-packages/Crypto/Random/_UserFriendlyRNG.py", line 38, in <module>
from Crypto.Random.Fortuna import FortunaAccumulator
File "/usr/lib/python2.7/site-packages/Crypto/Random/Fortuna/FortunaAccumulator.py", line 39, in <module>
import FortunaGenerator
File "/usr/lib/python2.7/site-packages/Crypto/Random/Fortuna/FortunaGenerator.py", line 35, in <module>
from Crypto.Util import Counter
File "/usr/lib/python2.7/site-packages/Crypto/Util/Counter.py", line 59, in <module>
from Crypto.Util import _counter
ImportError: cannot import name _counter
I see that _counter.pyd exists in Pycrypto folder. Why is this not getting picked?