简体   繁体   中英

how to use requests.post() with proxy authentication in python?

from bs4 import BeautifulSoup
import requests
from requests.auth import HTTPProxyAuth

url = "http://www.transtats.bts.gov/Data_Elements.aspx?Data=2" 
proxies = {"http":"xxx.xxx.x.xxx: port"}
auth = HTTPProxyAuth("username", "password")
r = requests.get(url, proxies=proxies, auth=auth)
soup = BeautifulSoup(r.text,"html.parser") 
viewstate_element = soup.find(id = "__VIEWSTATE").attrs 
viewstate = viewstate_element["value"]
eventvalidation_element = soup.find(id="__EVENTVALIDATION").attrs
eventvalidation = eventvalidation_element["value"]


data =     {'AirportList':"BOS",'CarrierList':"VX",'Submit':'Submit',"__EVENTTARGET":"","__EVENTARGUMENT":"","__EVENTVALIDATION":eventvalidation,"}
r = requests.post(url, proxies, auth, data )
print r

This code works fine when I use requests.get(url, proxies=proxies, auth=auth) , but what to do when there is some data that has to be sent through requests.post() under proxy authentication?

On behalf of Vikas Neha Ojha so all can see

proxies = {'http': 'http://username:password@ip:port', 'https': 'http://username:password@ip:port'}

and then

requests.post(url, proxies=proxies, data=data)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM