每次我尝试通过代理运行我的代码时,我总是得到这个错误。我已经通过了每一个关于如何让我的代码在proxy背后运行的链接,但我根本无法做到这一点。
import twython
import requests
TWITTER_APP_KEY = 'key' #supply the appropriate value
TWITTER_APP_KEY_SECRET = 'key-secret'
TWITTER_ACCESS_TOKEN = 'token'
TWITTER_ACCESS_TOKEN_SECRET = 'secret'
t = twython.Twython(app_key=TWITTER_APP_KEY,
app_secret=TWITTER_APP_KEY_SECRET,
oauth_token=TWITTER_ACCESS_TOKEN,
oauth_token_secret=TWITTER_ACCESS_TOKEN_SECRET,
client_args = {'proxies': {'http': 'proxy.company.com:10080'}})现在如果我这么做了
t = twython.Twython(app_key=TWITTER_APP_KEY,
app_secret=TWITTER_APP_KEY_SECRET,
oauth_token=TWITTER_ACCESS_TOKEN,
oauth_token_secret=TWITTER_ACCESS_TOKEN_SECRET,
client_args = client_args)
print t.client_args我只得到一个{}
当我尝试跑步的时候
t.update_status(status='See how easy this was?')我有这个问题:
Traceback (most recent call last):
File "<pyshell#40>", line 1, in <module>
t.update_status(status='See how easy this was?')
File "build\bdist.win32\egg\twython\endpoints.py", line 86, in update_status
return self.post('statuses/update', params=params)
File "build\bdist.win32\egg\twython\api.py", line 223, in post
return self.request(endpoint, 'POST', params=params, version=version)
File "build\bdist.win32\egg\twython\api.py", line 213, in request
content = self._request(url, method=method, params=params, api_call=url)
File "build\bdist.win32\egg\twython\api.py", line 134, in _request
response = func(url, **requests_args)
File "C:\Python27\lib\site-packages\requests-1.2.3-py2.7.egg\requests\sessions.py", line 377, in post
return self.request('POST', url, data=data, **kwargs)
File "C:\Python27\lib\site-packages\requests-1.2.3-py2.7.egg\requests\sessions.py", line 335, in request
resp = self.send(prep, **send_kwargs)
File "C:\Python27\lib\site-packages\requests-1.2.3-py2.7.egg\requests\sessions.py", line 438, in send
r = adapter.send(request, **kwargs)
File "C:\Python27\lib\site-packages\requests-1.2.3-py2.7.egg\requests\adapters.py", line 327, in send
raise ConnectionError(e)
ConnectionError: HTTPSConnectionPool(host='api.twitter.com', port=443): Max retries exceeded with url: /1.1/statuses/update.json (Caused by <class 'socket.gaierror'>: [Errno 11004] getaddrinfo failed)我到处都找过了。我已经尽我所能了。唯一可用的资源是:
https://groups.google.com/forum/#!topic/twython-talk/GLjjVRHqHng
https://github.com/fumieval/twython/commit/7caa68814631203cb63231918e42e54eee4d2273
https://groups.google.com/forum/#!topic/twython-talk/mXVL7XU4jWw
我在这里(在Stack Overflow上)也找不到任何主题。
请帮帮忙。希望有人回复。如果你已经这样做了,请帮助我一些代码示例。
发布于 2013-07-04 02:15:51
您的代码没有使用您的代理。该示例显示,您为普通HTTP指定了一个代理,但您的堆栈显示了一个HTTPSConnectionPool。您的本地计算机可能无法解析外部域。
尝试这样设置您的代理:
client_args = {'proxies': {'https': 'http://proxy.company.com:10080'}}发布于 2013-07-05 00:36:13
结合@t-8ch的回答(即您必须使用他定义的代理),您还应该意识到,到目前为止,requests (Twython的底层库)还不支持HTTPS上的代理。这是请求底层库urllib3的一个问题。据我所知,这是一个长期存在的问题。
最重要的是,阅读一点Twython的source解释了为什么t.client_args返回一个空字典。简而言之,如果您要打印t.client.proxies,您将会看到您的代理确实按照它们应该得到的方式进行了处理。
最后,在StackOverflow上抱怨你的工作场所,并在评论中链接到与你的GitHub用户名(和真实姓名)相关联的GitHub提交并不是最好的主意。谷歌对StackOverflow进行了彻底的索引,毫无疑问,其他人可能会发现这一点,并像我一样很容易地将它与你联系起来。最重要的是,该提交对Twython的当前行为完全没有影响。你追逐那个提交的作者是在没完没了地跑进兔子洞。
发布于 2013-07-03 20:27:19
看起来域名查找失败。假设您配置的DNS服务器可以解析Twitter的域名(当然可以),我假定您在DNS上查找proxy.company.com失败了。尝试按IP地址而不是按主机名使用代理。
https://stackoverflow.com/questions/17440456
复制相似问题