Python Proxy Settings

2019-05-04 00:06发布

I was using the wikipedia module in which you can get the information that is present about that topic on wikipedia. When I run the code it is unable to connect because of proxy. When I connected PC to a proxy free network it's working. It also happened while using the Beautiful soup module for scraping. I have tried to set environment variable like http://username:password@proxy_url:port but when the run the code in IDLE it's not working. Please help.

标签: python proxy
2条回答
Ridiculous、
2楼-- · 2019-05-04 00:54

It worked:

import os
os.environ["HTTPS_PROXY"] = "http://user_id:pass@proxy:port"
查看更多
我命由我不由天
3楼-- · 2019-05-04 01:06

If you don't want to store your password in code file:

import os

pxuser = "your.corporate.domain\\your_username"
pxpass = input(f"Password for {pxuser}: ")
env_px = f"http://{pxuser}:{pxpass}@your_proxy:port"
os.environ["HTTPS_PROXY"] = env_px
查看更多
登录 后发表回答