【问题标题】:Getting [Errno 110] 'Connection timed out' when trying to do get requests in python尝试在python中获取请求时获取[Errno 110]“连接超时”
【发布时间】:2018-08-20 10:12:09
【问题描述】:

我可以在 Firefox 浏览器中手动访问代码中提到的以下“URL”,并将 json 响应视为:

{
  "version" : "1.0",
  "email_address" : "xxxx@emailin.com"
}

但是当我尝试使用以下代码获取请求时,我收到连接超时错误。

import requests
URL='https://deviceconfig.pod1.pie.avatar.ext.hp.com/virtualprinter/v1/printers/emailaddress/AQAAAAFiGLv5GQAAAAGrHfgO'
proxies = {'http': '', 'https': ''}
headers={'User-Agent':'Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Firefox/52.0'}
try:
    r= requests.get(url=URL,proxies=proxies,verify=False,headers=headers)
    print r.status_code
    print r.content
except requests.exceptions.RequestException as e:
    print e.message

Error :
HTTPSConnectionPool(host='deviceconfig.pod1.pie.avatar.ext.hp.com', port=443): Max retries exceeded with url: /virtualprinter/v1/printers/emailaddress/AQAAAAFiGLv5GQAAAAGrHfgO (Caused by NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x7fd9f45080d0>: Failed to establish a new connection: [Errno 110] Connection timed out',))

【问题讨论】:

  • 您的网络有问题,可能与您的代理设置有关。

标签: python python-2.7 python-requests


【解决方案1】:

现在获取请求正在工作,通过使用端口号设置代理。

在上面的代码中添加了代理设置:

proxies = { 'http': 'web-proxy.xxxxxx.xx.com:8080','https': 'web-proxy.xxxxxx.xx.com:8080'}

Output :
200
{
  "version" : "1.0",
  "email_address" : "xxxx@emailin.com"
}

【讨论】:

    【解决方案2】:

    检查你的互联网连接,你可能没有正确连接到互联网,通过气隙连接真的很难

    【讨论】:

    • 最好有一个回答问题的答案。正如对问题的评论一样,这样的建议应该作为评论更好。
    • connecting through a air gap 抱歉,你到底在说什么?
    • 请问这与这个问题有什么关系? OP在任何地方都没有提到这样的事情。他们甚至说他们可以通过浏览器进行连接。
    • 我称没有连接到互联网,我认为气隙女巫很适合这种情况
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-01-22
    • 1970-01-01
    • 2014-07-18
    • 1970-01-01
    • 2013-10-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多