简体   繁体   English

Python 请求代理“str” object 没有属性“get”

[英]Python Requests Proxy 'str' object has no attribute 'get'

I am trying to do a request using a Proxy.我正在尝试使用代理进行请求。

My Code:我的代码:

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

The Error:错误:

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

Edit:编辑:

I missed a : .我错过了一个:

New Code:新代码:

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

You missed a : in your dictionary:您在字典中错过了一个:

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

If you have proxies = {'http' '1.1.1.1:1234'} , then proxies is actually a set with the single value of 'http1.1.1.1:1234' , hence the error.如果您有proxies = {'http' '1.1.1.1:1234'} ,那么proxies实际上是一个具有单个值的set 'http1.1.1.1:1234' ,因此会出现错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM