简体   繁体   English

为什么我得到“no_proxy = proxies.get('no_proxy') if proxies is not None else None AttributeError: 'str' object has no attribute 'get'”

[英]Why do i get "no_proxy = proxies.get('no_proxy') if proxies is not None else None AttributeError: 'str' object has no attribute 'get'"

I have checked other posts but they do not seem to resolve this.我检查了其他帖子,但他们似乎没有解决这个问题。

this is my code.这是我的代码。

  def main():
    while True==True:

        random_proxy = random.choice(read)

        proxies = {
            proxy_type: random_proxy
        }

        response = requests.get('https://manacube.com/play/', cookies=cookies, proxies=proxies, headers=headers)

        if response.status_code == 200:
            print("Page View Sent (Code 200)")
        else:
            print("Error")

for x in range (int(t)):
    Thread(target=main).start()

THE ERROR IM GETTING IS:我得到的错误是:

Traceback (most recent call last):
  File "C:\Users\name\AppData\Local\Programs\Python\Python38\lib\threading.py", line 932, in _bootstrap_inner
    self.run()
  File "C:\Users\name\AppData\Local\Programs\Python\Python38\lib\threading.py", line 870, in run
    self._target(*self._args, **self._kwargs)
  File "bot.py", line 49, in main
    response = requests.get('https://url.com/play/', cookies=cookies, proxies=random_proxy, headers=headers)
  File "C:\Users\name\AppData\Local\Programs\Python\Python38\lib\site-packages\requests\api.py", line 75, in get
    return request('get', url, params=params, **kwargs)
  File "C:\Users\name\AppData\Local\Programs\Python\Python38\lib\site-packages\requests\api.py", line 61, in request
    return session.request(method=method, url=url, **kwargs)
  File "C:\Users\mazin\AppData\Local\Programs\Python\Python38\lib\site-packages\requests\sessions.py", line 519, in request
    settings = self.merge_environment_settings(
  File "C:\Users\name\AppData\Local\Programs\Python\Python38\lib\site-packages\requests\sessions.py", line 700, in merge_environment_settings
    no_proxy = proxies.get('no_proxy') if proxies is not None else None
AttributeError: 'str' object has no attribute 'get'

I am not sure if this is a dumb error but i am new at python so please do not make fun of me, please help if you can, i want to choose a random proxy out of proxies.txt and use it every request.我不确定这是否是一个愚蠢的错误,但我是 python 的新人所以请不要取笑我,如果可以的话请帮忙,我想从 proxies.txt 中选择一个随机代理并在每个请求中使用它。

so所以

request 1: 111.68.31.155:8080 request 2: 203.210.84.198:8080 request 3: 150.136.120.227:3128请求1:111.68.31.155:8080 请求2:203.210.84.198:8080 请求3:150.136.120.227:3128

I tried this and it worked with me我试过了,它对我有用

It's using:它正在使用:

pro = {
       'http://': random_proxy,
       'https://': random_proxy
     }

Instead of:代替:

proxies = {
            proxy_type: random_proxy
        }

暂无
暂无

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

相关问题 AttributeError: 'str' 对象没有属性 'get' 或最多返回 None - AttributeError: 'str' object has no attribute 'get' or return None at best 为什么我在这个python代码中得到一个“AttributeError:'str'对象没有属性'write'” - Why do I get an “AttributeError: 'str' object has no attribute 'write' ” in this python code Python 请求代理“str” object 没有属性“get” - Python Requests Proxy 'str' object has no attribute 'get' AttributeError: 'NoneType' object 没有属性 'get' - 当我有数据并且没有字段为 None 时如何解决? - AttributeError: 'NoneType' object has no attribute 'get' - How to solve it when I even have the data and no field is None? / share / 4'str'对象上的AttributeError没有属性'get' - AttributeError at /share/4 'str' object has no attribute 'get' AttributeError: 'str' 对象没有属性 'get' ocr - AttributeError: 'str' object has no attribute 'get' ocr 为什么会出现 AttributeError: 'NoneType' object has no attribute 'something'? - Why do I get AttributeError: 'NoneType' object has no attribute 'something'? Python AttributeError:“ str”对象没有属性“ get” - Python AttributeError: 'str' object has no attribute 'get' AttributeError:'str'对象没有属性'get' - AttributeError: 'str' object has no attribute 'get' AttributeError:'str'对象在django中没有属性'get' - AttributeError: 'str' object has no attribute 'get' in django
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM