Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/292.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python tweepy.error.TweepError:Twitter错误响应:状态代码=401_Python_Tweepy - Fatal编程技术网

Python tweepy.error.TweepError:Twitter错误响应:状态代码=401

Python tweepy.error.TweepError:Twitter错误响应:状态代码=401,python,tweepy,Python,Tweepy,我使用的是python 3.4.3,我遵循了链接上的所有说明: 我尝试从链接运行代码时出错 import tweepy consumer_key = 'xxx' consumer_secret = 'xxx' access_token = 'xxx' access_token_secret = 'xxx' auth = tweepy.OAuthHandler(consumer_key, consumer_secret) auth.set_access_token(access_token, a

我使用的是python 3.4.3,我遵循了链接上的所有说明: 我尝试从链接运行代码时出错

import tweepy

consumer_key = 'xxx'
consumer_secret = 'xxx'
access_token = 'xxx'
access_token_secret = 'xxx'
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)

api = tweepy.API(auth, wait_on_rate_limit = True, wait_on_rate_limit_notify =         True)
ids = api.friends_ids()
urls = []

for friend in ids:
statuses = api.user_timeline(id=friend, count=200)
for status in statuses:
    if status.entities and status.entities['urls']:
        for url in status.entities['urls']:
            urls.append((url['expanded_url'], status.author.screen_name))
with open('urls.csv', 'w') as f:
for url in urls:
    f.write(url[0] + ',' + url[1] + '\n')
f.close()

错误
回溯(最近一次呼叫最后一次):
文件“C:/Python34/file11.py”,第11行,在
ids=api.friends\u ids()
文件“C:\Python34\Lib\site packages\tweepy\binder.py”,第239行,在调用中
返回方法execute()
文件“C:\Python34\Lib\site packages\tweepy\binder.py”,第223行,在execute中
raise TweepError(错误消息,响应)
tweepy.error.TweepError:Twitter错误响应:状态代码=401

401是
未经授权的状态代码。这意味着您的凭据(在本例中,您的消费者/访问令牌)无效。按照说明再次尝试正确地重新创建凭据

编辑:如果您运行的代码与发布的代码完全相同,请注意,您必须将所有键替换为使用上述链接生成的键

编辑:

正如LetsPlayYahtzee在下面的评论中所指出的,这也可能意味着你无法访问你所请求的数据


例如,当您试图从私人用户检索推文时,可能会发生这种情况。

错误状态401通常意味着未授权(无论出于何种原因)@AndréSchild,但是,我在谷歌搜索了如何获取推特api的身份验证号,在图像中,我遵循了移动验证的步骤,并尝试将一些链接放入URL[ ]根据您是否知道我可能错过的任何其他具体步骤双重和三重检查身份验证设置/编号目前已经这样做了3-4个小时通常
未经授权
状态代码意味着您无权从用户检索数据,因为该用户可能在twi上的个人资料上设置了某种隐私规则滴答声
Traceback (most recent call last):
  File "C:/Python34/file11.py", line 11, in <module>
    ids = api.friends_ids()
  File "C:\Python34\Lib\site-packages\tweepy\binder.py", line 239, in _call
    return method.execute()
  File "C:\Python34\Lib\site-packages\tweepy\binder.py", line 223, in execute
    raise TweepError(error_msg, resp)
tweepy.error.TweepError: Twitter error response: status code = 401