Python请求模块

时间:2014-04-15 20:43:22

标签: python python-requests

我需要使用Python请求模块来调用Web请求。

我要求在机器上提供请求例如:55.84.201.228。当我通过浏览器输入它时,它工作正常,我能够查看网页..

但是当我使用requests.get时,它不起作用..它有套接字错误的错误..

>>> import requests
>>> r = requests.get('https://55.84.201.228')


Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python2.7/dist-packages/requests/api.py", line 55, in get
    return request('get', url, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/requests/api.py", line 44, in request
    return session.request(method=method, url=url, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/requests/sessions.py", line 383, in request
    resp = self.send(prep, **send_kwargs)
  File "/usr/local/lib/python2.7/dist-packages/requests/sessions.py", line 486, in send
    r = adapter.send(request, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/requests/adapters.py", line 378, in send
    raise ConnectionError(e)
requests.exceptions.ConnectionError: HTTPSConnectionPool(host='55.84.201.228', port=443): Max retries exceeded with url: / (Caused by <class 'socket.error'>: [Errno 110] Connection timed out)

如何解决此问题?

>>>r = requests.get('https://www.cnn.com')

这很好用。

1 个答案:

答案 0 :(得分:-1)

我在这里做了一个疯狂的猜测,因为我无法访问您的计算机,但是从经验来看,因为您使用的是https,我认为是一些测试服务器尝试

r = requests.get('https://55.84.201.228', verify=False)

根据the documentation默认情况下,证书验证已启用。