Python 请求代理 'str' 对象没有属性 'get'

Python Requests Proxy 'str' object has no attribute 'get'

我正在尝试使用代理发送请求。

我的代码:

import requests
proxies = {'http' '1.1.1.1:1234'}
r = requests.get('https://httpbin.org/ip', proxies=proxies)
print(r.text)

错误:

    no_proxy = proxies.get('no_proxy') if proxies is not None else None
    AttributeError: 'set' object has no attribute 'get'

编辑:

我错过了一个:

新代码:

import requests
proxies = {'http': '1.1.1.1:1234'}
r = requests.get('https://httpbin.org/ip', proxies=proxies)
print(r.text)

您在字典中遗漏了一个 :

proxies = {'http': '1.1.1.1:1234'}

如果您有 proxies = {'http' '1.1.1.1:1234'},那么 proxies 实际上是一个 set,具有单个值 'http1.1.1.1:1234',因此会出现错误。