# Python request 代理的奇怪问题

**URL:** <https://forum.freemdict.com/t/topic/8499>\
**Category:** 技术交流与词典编修\
**Created:** [2021 年9 月 27 日 10:39 UTC](https://forum.freemdict.com/t/topic/8499 "2021-09-27T10:39:09Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

作者： ![getdicter](https://forumcdn.freemdict.com/letter_avatar_proxy/v4/letter/g/e9a140/32.png) [@getdicter](https://forum.freemdict.com/u/getdicter)\
发布日期： [2021 年9 月 27 日 10:39 UTC](https://forum.freemdict.com/t/topic/8499/1 "2021-09-27T10:39:09Z")

</div>

import requests

proxy = ‘127.0.0.1:9999’  
proxies = {  
“http”: proxy,  
# “https”: “https://” + proxy  
}  
try:  
url = ‘[http://httpbin.org/get](http://httpbin.org/get)’  
url = ‘[https://www.google.com](https://www.google.com)’  
response = requests.get(url=url, headers=None, proxies=proxies, verify=False)  
print(response.text)  
except requests.exceptions.ConnectionError as e:  
print(‘Error’, e.args)

第一url，就是测试不用代理都可以访问而且已经显示代理正常  
一换第二个url访问google之类，就马上错误提示  
Error (MaxRetryError(“HTTPSConnectionPool(host=‘[www.google.com](http://www.google.com)’, port=443): Max retries exceeded with url: / (Caused by NewConnectionError(‘\<urllib3.connection.HTTPSConnection object at 0x000001905920FC48\>: Failed to establish a new connection: [WinError 10060] 由于连接方在一段时间后没有正确答复或连接的主机没有反应，连接尝试失败。’))”),)

Process finished with exit code 0  
以为是代理问题，结果一换成  
urllib.request，就啥事都没有。。。。很无语，还是我个人品问题？不过以前这模块都是好好的啥就忽然不行了。。。

---

<div class="post-metadata">

作者： ![okayer](https://forumcdn.freemdict.com/user_avatar/forum.freemdict.com/okayer/32/16083_2.png) [@okayer](https://forum.freemdict.com/u/okayer)\
发布日期： [2021 年9 月 27 日 11:13 UTC](https://forum.freemdict.com/t/topic/8499/2 "2021-09-27T11:13:45Z")

</div>

```auto
import requests

proxy = 'http://127.0.0.1:9999'
proxies = {
        "http": proxy,
        "https": proxy,
}

try:
        url = 'https://www.google.com'
        response = requests.get(url=url, headers=None, proxies=proxies, verify=False)
        print(response.text)
except requests.exceptions.ConnectionError as e:
        print('Error', e.args)

```

如果不行，那就是你代理的问题了

---

<div class="post-metadata">

作者： ![getdicter](https://forumcdn.freemdict.com/letter_avatar_proxy/v4/letter/g/e9a140/32.png) [@getdicter](https://forum.freemdict.com/u/getdicter)\
发布日期： [2021 年9 月 28 日 01:56 UTC](https://forum.freemdict.com/t/topic/8499/3 "2021-09-28T01:56:03Z")

</div>

居然又变了代理设置，现在没有问题。  
不过新问题又来了

Please Wait... | Cloudflare 所谓5秒问题搜索一下都说要另安装其它模拟，真奇怪request不是封装urllib.request吗？直接用urllib.request #! /usr/bin/env python3 # \_\_author\_\_=wei import urllib.parse import ssl import urllib.request

SETTING\_PROXY = 1  
HTTPS = 1  
if HTTPS:  
url = ‘[https://somesite](https://somesite)’  
else:  
url = ‘[http://www.baidu.com/](http://www.baidu.com/)’  
user\_agent = ‘Mozilla/4.0 (compatible; MSIE 5.5; Windows NT)’  
values = {‘name’: ‘xxx1’, ‘email’: ‘fuck@qq.com’, ‘password’: ‘123456’}  
headers = {‘User-Agent’: user\_agent}  
if SETTING\_PROXY:  
ssl.\_create\_default\_https\_context = ssl.\_create\_unverified\_context # [python3中使用urlopen()报错的解决方法\_悠闲独自在的博客-CSDN博客\_urlopen error](https://blog.csdn.net/qq_25403205/article/details/81258327)  
if HTTPS:  
proxy\_support = urllib.request.ProxyHandler({“https”: “172.0.0.1:9999”})  
else:  
proxy\_support = urllib.request.ProxyHandler({“http”: “172.0.0.1:9999”})  
opener = urllib.request.build\_opener(proxy\_support)  
urllib.request.install\_opener(opener)  
data = urllib.parse.urlencode(values).encode(  
encoding=‘UTF8’) # if you don’t encode utf, TypeError: POST data should be bytes, an iterable of bytes, or a file object. It cannot be of type str.  
req = urllib.request.Request(url, data=None, headers=headers)  
response = urllib.request.urlopen(req)  
the\_page = response.read()  
print(the\_page.decode(“utf8”))

---

<div class="post-metadata">

作者： ![James1](https://forumcdn.freemdict.com/letter_avatar_proxy/v4/letter/j/c67d28/32.png) [@James1](https://forum.freemdict.com/u/James1)\
发布日期： [2021 年9 月 28 日 04:39 UTC](https://forum.freemdict.com/t/topic/8499/4 "2021-09-28T04:39:14Z")

</div>

[https://www.google.co.uk/search?q=requests+module+in+python&client=safari&channel=iphone\_bm&source=hp&ei=M5xSYdefFvaXr7wP9P230Ak&oq=requests+mkdule&gs\_lcp=ChFtb2JpbGUtZ3dzLXdpei1ocBABGAAyBAgAEA0yBAgAEA0yBAgAEA0yBAgAEA0yBAgAEA0yBAgAEA0yBAgAEA0yBAgAEA06AggpOgQIKRAKOg4IABDqAhCPARCMAxDlAjoOCC4QgAQQsQMQgwEQkwI6CAgAEIAEELEDOgsIABCABBCxAxCDAToICAAQsQMQgwE6CAguEIAEELEDOgUILhCABDoFCAAQsQM6CwguEIAEELEDEIMBOgUIABCABDoGCAAQFhAeOgUIIRCgAVDZClj4JmD9L2gBcAB4AIAB9QGIAcsQkgEFNi43LjOYAQCgAQGwAQc&sclient=mobile-gws-wiz-hp](https://www.google.co.uk/search?q=requests+module+in+python&client=safari&channel=iphone_bm&source=hp&ei=M5xSYdefFvaXr7wP9P230Ak&oq=requests+mkdule&gs_lcp=ChFtb2JpbGUtZ3dzLXdpei1ocBABGAAyBAgAEA0yBAgAEA0yBAgAEA0yBAgAEA0yBAgAEA0yBAgAEA0yBAgAEA0yBAgAEA06AggpOgQIKRAKOg4IABDqAhCPARCMAxDlAjoOCC4QgAQQsQMQgwEQkwI6CAgAEIAEELEDOgsIABCABBCxAxCDAToICAAQsQMQgwE6CAguEIAEELEDOgUILhCABDoFCAAQsQM6CwguEIAEELEDEIMBOgUIABCABDoGCAAQFhAeOgUIIRCgAVDZClj4JmD9L2gBcAB4AIAB9QGIAcsQkgEFNi43LjOYAQCgAQGwAQc&sclient=mobile-gws-wiz-hp)

---

<div class="post-metadata">

作者： ![getdicter](https://forumcdn.freemdict.com/letter_avatar_proxy/v4/letter/g/e9a140/32.png) [@getdicter](https://forum.freemdict.com/u/getdicter)\
发布日期： [2021 年9 月 29 日 02:13 UTC](https://forum.freemdict.com/t/topic/8499/5 "2021-09-29T02:13:01Z")

</div>

> [@getdicter](#):
>
> Cloudflare

> <https://stackoverflow.com/questions/49087990/python-request-being-blocked-by-cloudflare>

几本无解了。。。
