Tweepy Error: Failed to send request

tweepy

#1

When I try to run basic hello tweepy,

auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
api = tweepy.API(auth)

public_tweets = api.home_timeline()
for tweet in public_tweets:
print tweet.text

I get the following error,

tweepy.error.TweepError: Failed to send request: ‘module’ object has no attribute ‘HTTPMessage’

But when my friend was able to run the same script without any errors but it’s from another IP address.
Any ideas what might be causing this error just for me?


#2

(Edited to remove username mentions - don’t do that unless responding specifically to someone, since not everyone has the same skills or time to reply)


#3

Most likely something wrong with python package install / environment.

pip install --upgrade --force-reinstall tweepy

might work!

(I know tweepy definitely works on top of Conda if there’s any other missing dependencies or something)


#4

@IgorBrigadir Thank you! I tried your fix, but unfortunately, it still throws the same error.

But I found out that the error is raising from tweepy’s binder.py . Below is the error,


#5

Strange - tweepy depends on requests, requests_oauthlib, six - if those aren’t installed it might be throwing errors.

Try installing with:
pip install git+https://github.com/tweepy/tweepy.git

I notice it’s python 2.7: I’m using python 3.5 with tweepy and everything seems to be working fine. Not sure if that’s any help.


#6

Sorry, that didn’t work too. Is it may be because my IP is blocked? If that’s the case, how to check that my IP is blocked? It was working perfectly fine till few days back. After that I didn’t disturb tweepy installation, but suddenly it starts throwing this error.

I tried installing it from git as you mentioned but it throws this error:

Btw, could you please tell me how to make tweepy use python3.5 instead of 2.7? Maybe that could work.


#7

No, “‘module’ has no attribute” type errors are definitely nothing to do with Twitter API. It’s a python issue.

Looks like previous command was trying to install system wide, and didn’t work properly…

I’d recommend installing conda https://www.continuum.io/downloads (either 2.7 or 3.5) and then installing tweepy with pip once you have a conda environment instead of installing packages system wide. It definitely works with that.


#8

@IgorBrigadir Thank you very much my dear friend :smiley:
was able to solve the issue after installing Anaconda 3.4 and then

pip3 install tweepy

Have a nice day!