質問

Here is the code I am using, mainly to test to see if everything is authorizing correctly, and to try to post for the first time.

import tweepy

CONSUMER_KEY ="XXXXXXXXXXXXXXXXXXXXXXXXX"
CONSUMER_SECRET = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"   
ACCESS_KEY = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"    
ACCESS_SECRET = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"

auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
auth.set_access_token(ACCESS_KEY, ACCESS_SECRET)

api = tweepy.API(auth)
api.update_status('Updating using OAuth authentication via Tweepy!')

and here is the error I am getting when I run it from the command line:

C:\Users\CJ\Desktop>python tweeper.py
Traceback (most recent call last):
  File "tweeper.py", line 13, in <module>
    api.update_status('Updating using OAuth authentication via Tweepy!')
  File "C:\python33\lib\site-packages\tweepy-1.4-py3.3.egg\tweepy\binder.py", li
ne 153, in _call
tweepy.error.TweepError: Twitter error response: status code = 401

I've searched stack overflow, dev.twitter and google for everything I could regarding the 401 error from Twitter and line 153 from tweepy\binder.py, but I couldn't find much of anything specific to my problem.

One thing I tried was inserting the callback url I used with dev.twitter after CONSUMER_SECRET, such that it read:

    auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET, CALLBACK_URL)

but that gave me the same error. Thanks in advance.

役に立ちましたか?

解決

401 means "unauthorized" which means OAuth is not working for your program. There are many, many reasons why this could be true given the limited code you've shared so far.

Here is a Twitter Dev thread on a similar situation with one specific suggestion: https://dev.twitter.com/discussions/1403

But if that doesn't happen to solve your problem, I'd suggest you include a dump of the HTTP messages sent and received by your program before following up here. That will provide very useful detail to narrow down the possibilities.

If tweepy doesn't have a tracing option, you might find Fiddler (http://www.telerik.com/fiddler) easy to use (and useful for future development projects), as you do seem to be running Windows.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top