Ampare1987 2022-02-27 20:23 采纳率: 55.6%
浏览 53
已结题

tweepy初学者hello world就出错,大家找找原因

问题遇到的现象和发生背景

我按照https://blog.csdn.net/zhurui_idea/article/details/56481382的方法,写了第一段代码

问题相关代码,请勿粘贴截图
#导入tweepy
import tweepy
 
#填写twitter提供的开发Key和secret
consumer_key = 'xxxxxxxxxxxxxxxxx'
consumer_secret = 'xxxxxxxxxxxxxxxxxxxxxxxxx'
access_token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
access_token_secret = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
 
#提交你的Key和secret
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
运行结果及报错内容

在PyCharm中运行,报错如下

C:\Users\ampar\.virtualenvs\PyCharmLearningProject\Scripts\python.exe "I:/Hands-On Machine Learning with Scikit-Lean/Twitter2.py"
Traceback (most recent call last):
  File "C:\Users\ampar\.virtualenvs\PyCharmLearningProject\lib\site-packages\urllib3\connection.py", line 174, in _new_conn
    conn = connection.create_connection(
  File "C:\Users\ampar\.virtualenvs\PyCharmLearningProject\lib\site-packages\urllib3\util\connection.py", line 95, in create_connection
    raise err
  File "C:\Users\ampar\.virtualenvs\PyCharmLearningProject\lib\site-packages\urllib3\util\connection.py", line 85, in create_connection
    sock.connect(sa)
TimeoutError: [WinError 10060] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\ampar\.virtualenvs\PyCharmLearningProject\lib\site-packages\urllib3\connectionpool.py", line 703, in urlopen
    httplib_response = self._make_request(
  File "C:\Users\ampar\.virtualenvs\PyCharmLearningProject\lib\site-packages\urllib3\connectionpool.py", line 386, in _make_request
    self._validate_conn(conn)
  File "C:\Users\ampar\.virtualenvs\PyCharmLearningProject\lib\site-packages\urllib3\connectionpool.py", line 1040, in _validate_conn
    conn.connect()
  File "C:\Users\ampar\.virtualenvs\PyCharmLearningProject\lib\site-packages\urllib3\connection.py", line 358, in connect
    conn = self._new_conn()
  File "C:\Users\ampar\.virtualenvs\PyCharmLearningProject\lib\site-packages\urllib3\connection.py", line 186, in _new_conn
    raise NewConnectionError(
urllib3.exceptions.NewConnectionError: <urllib3.connection.HTTPSConnection object at 0x0000026EA87B1190>: Failed to establish a new connection: [WinError 10060] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\ampar\.virtualenvs\PyCharmLearningProject\lib\site-packages\requests\adapters.py", line 440, in send
    resp = conn.urlopen(
  File "C:\Users\ampar\.virtualenvs\PyCharmLearningProject\lib\site-packages\urllib3\connectionpool.py", line 785, in urlopen
    retries = retries.increment(
  File "C:\Users\ampar\.virtualenvs\PyCharmLearningProject\lib\site-packages\urllib3\util\retry.py", line 592, in increment
    raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='api.twitter.com', port=443): Max retries exceeded with url: /1.1/statuses/update.json?status=hello+python (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x0000026EA87B1190>: Failed to establish a new connection: [WinError 10060] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond'))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\ampar\.virtualenvs\PyCharmLearningProject\lib\site-packages\tweepy\api.py", line 216, in request
    resp = self.session.request(
  File "C:\Users\ampar\.virtualenvs\PyCharmLearningProject\lib\site-packages\requests\sessions.py", line 529, in request
    resp = self.send(prep, **send_kwargs)
  File "C:\Users\ampar\.virtualenvs\PyCharmLearningProject\lib\site-packages\requests\sessions.py", line 645, in send
    r = adapter.send(request, **kwargs)
  File "C:\Users\ampar\.virtualenvs\PyCharmLearningProject\lib\site-packages\requests\adapters.py", line 519, in send
    raise ConnectionError(e, request=request)
requests.exceptions.ConnectionError: HTTPSConnectionPool(host='api.twitter.com', port=443): Max retries exceeded with url: /1.1/statuses/update.json?status=hello+python (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x0000026EA87B1190>: Failed to establish a new connection: [WinError 10060] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond'))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "I:\Hands-On Machine Learning with Scikit-Lean\Twitter2.py", line 13, in <module>
    api.update_status('hello python')
  File "C:\Users\ampar\.virtualenvs\PyCharmLearningProject\lib\site-packages\tweepy\api.py", line 46, in wrapper
    return method(*args, **kwargs)
  File "C:\Users\ampar\.virtualenvs\PyCharmLearningProject\lib\site-packages\tweepy\api.py", line 1121, in update_status
    return self.request(
  File "C:\Users\ampar\.virtualenvs\PyCharmLearningProject\lib\site-packages\tweepy\api.py", line 222, in request
    raise TweepyException(f'Failed to send request: {e}').with_traceback(sys.exc_info()[2])
  File "C:\Users\ampar\.virtualenvs\PyCharmLearningProject\lib\site-packages\tweepy\api.py", line 216, in request
    resp = self.session.request(
  File "C:\Users\ampar\.virtualenvs\PyCharmLearningProject\lib\site-packages\requests\sessions.py", line 529, in request
    resp = self.send(prep, **send_kwargs)
  File "C:\Users\ampar\.virtualenvs\PyCharmLearningProject\lib\site-packages\requests\sessions.py", line 645, in send
    r = adapter.send(request, **kwargs)
  File "C:\Users\ampar\.virtualenvs\PyCharmLearningProject\lib\site-packages\requests\adapters.py", line 519, in send
    raise ConnectionError(e, request=request)
tweepy.errors.TweepyException: Failed to send request: HTTPSConnectionPool(host='api.twitter.com', port=443): Max retries exceeded with url: /1.1/statuses/update.json?status=hello+python (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x0000026EA87B1190>: Failed to establish a new connection: [WinError 10060] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond'))

Process finished with exit code 1

请问是什么原因,如何解决,谢谢大家!

  • 写回答

2条回答 默认 最新

  • Julian_0115 2022-03-01 19:18
    关注

    您先看一下楼上的回答为什么审核不通过,再看我的回答。“上网加速”有两种方式,一种是智能的,一种是非智能的。你要选择非智能的哪一种,就好了。明白了吗,不明白你可以私信我我给你做确切的详细解答。

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

问题事件

  • 已结题 (查看结题原因) 3月2日
  • 已采纳回答 3月1日
  • 创建了问题 2月27日

悬赏问题

  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料