【问题标题】:unable to connect HTTPS url in python无法在python中连接HTTPS url
【发布时间】:2018-05-11 23:11:46
【问题描述】:
#!/usr/bin/python
import requests
from requests.auth import HTTPBasicAuth
requests.get('url', auth=HTTPBasicAuth('XXXX','XXXX'))

我遇到错误

(Caused by ProxyError('Cannot connect to proxy.', error(111, 'Connection refused')
requests.exceptions.ConnectionError: HTTPSConnectionPool(host='XXXX', port=443): Max retries exceeded with url

【问题讨论】:

  • 也许在发布问题之前格式化您的代码?
  • 抱歉,您现在可以查看
  • url 应该是一个变量吗?在您的代码中,它作为字符串 'url' 传递。
  • 实际上我正在放置我的网址,我只是在发布问题时将网址保留为占位符

标签: python https


【解决方案1】:

根据错误,您使用 HTTPBasicAuth 代替代理(也许是那个公司代理?)。 尝试在请求之前设置代理凭据。

$ export http_proxy='http://myproxy.example.com:1234'
$ python request.py  # Using http://myproxy.example.com:1234 as a proxy

如果您使用公司代理,请告诉我。

【讨论】:

  • 我已经设置了代理我可以连接一个http代理,问题是连接到https代理(比如应用程序动态REST API)
  • 有时htts代理使用http,试试:export https_proxy='http://myproxy.example.com:1234
  • 它可以工作,但作为响应,我只是获得了 的状态,但实际上 URL 输出了一个 xml 响应,如何获得呢?
  • 这很好,因为您只需发送一个请求,就会得到 200“OK”响应。现在你应该解析一个 url。 from xml.etree import ElementTree可以帮到你
猜你喜欢
  • 2018-01-24
  • 1970-01-01
  • 2013-05-19
  • 2015-10-21
  • 1970-01-01
  • 1970-01-01
  • 2019-03-05
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多