How to use requests library without system-configured proxies

|▌冷眼眸甩不掉的悲伤 提交于 2021-02-10 14:27:27

问题


If I supply None or an empty dict to the proxies parameter, requests will automatically fall back to the proxies configured for the operating system as obtained through urllib.request.getproxies() (Python 3) / urllib.getproxies().

import requests
r = requests.get('http://google.com', proxies = {}) # or = None...
print(r.text)

Specifying proxies = { 'http': False } will even cause requests to hang completely for whatever weird reason.

So how do I direct requests to perform HTTP requests directly, without any proxy ?


回答1:


Turns out you have to use an empty string for the protocol you want to use a direct connection:

r = requests.get('http://google.com', proxies = { 'http': '', ... })

Weird, but that's life.



来源:https://stackoverflow.com/questions/25303005/how-to-use-requests-library-without-system-configured-proxies

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!