Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python Proxy Settings

Tags:

python

proxy

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.

like image 587
Abhinav Anand Avatar asked Mar 23 '17 15:03

Abhinav Anand


2 Answers

It worked:

import os
os.environ["HTTPS_PROXY"] = "http://user_id:pass@proxy:port"
like image 100
Abhinav Anand Avatar answered Sep 23 '22 03:09

Abhinav Anand


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
like image 21
Ilis Avatar answered Sep 23 '22 03:09

Ilis