tweepy.error.TweepError:Twitter错误响应:状态码= 403使用dockerfile时

时间:2018-07-19 13:33:54

标签: python docker dockerfile tweepy http-status-code-403

我正在尝试使用Dockefile运行python tweepy脚本。

这是我的Dockerfile:

FROM python:3.6

RUN pip install tweepy

RUN pip install pymongo
RUN pip install asyncio

ADD tweepy_twitter_stream_v0.6.py /


CMD [ "python", "./tweepy_twitter_stream_v0.6.py" ]

tweepy_twitter_stream_v0.6.py是我要在docker映像上运行的python脚本。 该文件搜索主题标签,并将推文插入mongoDB:

# Send a request to Twitter's server and save the data on tweepy iterator using hashtag_name.
for tweet in tweepy.Cursor(api.search,q=hashtag_name,count=100,wait_on_rate_limit=True ,wait_on_rate_limit_notify= True).items():

        # Convert tweepy object into json format 
        tweet_as_json = tweet._json  
        # Insert tweet to mongoDB 
        tweets.insert_one(tweet_as_json)

当我在Jupyter笔记本上运行它时,它工作得非常好 但是,当我尝试使用dockerfile运行它时,出现以下错误消息:

    for tweet in tweepy.Cursor(api.search,q=hashtag_name,count=100,wait_on_rate_limit=True ,wait_on_rate_limit_notify= True).items():
  File "/usr/local/lib/python3.6/site-packages/tweepy/cursor.py", line 49, in __next__
    return self.next()
  File "/usr/local/lib/python3.6/site-packages/tweepy/cursor.py", line 197, in next
    self.current_page = self.page_iterator.next()
  File "/usr/local/lib/python3.6/site-packages/tweepy/cursor.py", line 108, in next
    data = self.method(max_id=self.max_id, parser=RawParser(), *self.args, **self.kargs)
  File "/usr/local/lib/python3.6/site-packages/tweepy/binder.py", line 250, in _call
    return method.execute()
  File "/usr/local/lib/python3.6/site-packages/tweepy/binder.py", line 234, in execute
    raise TweepError(error_msg, resp, api_code=api_error_code)
tweepy.error.TweepError: Twitter error response: status code = 403

这就是我使用docker的方式:

  • 构建docker文件
  • 运行docker映像
  •  --

都进展顺利,我得到了图像名称。然后我在Docker工具箱命令行中运行了该命令:

    docker run f384c515d331 

f384c515d331是图像名称。我仍然收到相同的错误消息。

请帮助这确实令人沮丧;(

1 个答案:

答案 0 :(得分:0)

HTTP 403表示请求的禁止状态。

  

HTTP 403是HTTP服务器传达给客户端的标准HTTP状态代码,用于指示服务器理解了该请求,但由于与授权相关的某些原因而无法满足该请求。

您的API调用可能缺少正确的身份验证,尽管很难看到完整的代码。请查看Tweepy authentication guide.

相关问题