@@ -86,52 +86,46 @@ Other Enhancements
8686
8787If `python-requests` library is installed try to use it first. If not, continue using urllib
8888The :meth:`DataFrame.read_csv`, :meth:`DataFrame.read_html`, :meth:`DataFrame.read_json`,
89- :meth:`DataFrame.read_excel` now allow optional param of ``req_session`` to pass in requests.Session()
89+ :meth:`DataFrame.read_excel` now allow optional param of ``url_params`` to pass in
90+ parameters for basic auth, disable ssl strict check or even a requests.Session() object
9091
9192
9293.. ipython:: python
9394 import pandas as pd
94- from requests import Session
9595
96- # req_session is optional parameter
96+ # url_params is optional parameter
9797 df = pd.read_csv('https://uname:pwd@aa.com/bb.csv') # now url can contain username and pwd
9898
99- # custom auth can be implemented
100- s = Session()
99+ # Basic Auth
100+ df = pd.read_csv('https://aa.com/bb.csv', url_params={ 'auth': ('john', 'pwd') } ) # now url can contain username and pwd
101+
102+ # Basic Auth And disable verification of SSL certificate eg: testing
103+ up = { 'auth': ('john', 'pwd') , 'verify' : False}
104+ df = pd.read_csv('https://aa.com/bb.csv', url_params=up ) # now url can contain username and pwd
105+
106+ # Optionally, A requests.Session() can also be passed into url_params
107+ import requests
108+ s = requests.Session()
101109 s.auth = MyAuthProvider('secret-key') # custom auth provider supported by requests
102- df = pd.read_csv(url, req_session =s)
110+ df = pd.read_csv(url, url_params =s)
103111
104- # optional advanced scenarios: basic auth, timeout, disable ssl certificate verification, proxy, etc
112+ # For advanced users, this may provide extensibility. However, testing on pandas side is limited to basic scenarios
113+ # here is an example of advanced scenario
105114 s = Session()
106115 s.auth = ('darth', 'l0rd') # if user wants to perform basic auth Skip if url itself contains username and pwd
107116 s.timeout = (3.05, 27) # if user wants to modify timeout
108117 s.verify = False # if user wants to disable ssl cert verification
109118 s.headers.update( {'User-Agent': 'Custom user agent'} ) # extensible to set any custom header needed
110119 s.proxies = { 'http': 'http://a.com:100'} # if user has proxies
111120 s.cert = '/path/client.cert' # if custom cert is needed
112- df = pd.read_csv( 'https://aa.com/bbb.csv', req_session=s)
113-
114- # support verbs other than 'GET' such as 'POST' using requests.PreparedRequest
115- r = Request('POST', 'http://joker:pwd@nlp_service.api/email_sentiment_extract?out=json')
116- prepped = req.prepare()
117- prepped.body = 'from: aaa@aa.bb\nto: cc@dd.ee\nsubject:Complaint letter\n\nbody: I am feeling :(' # multiple lines
118- df = pd.read_json( prepped) # minor update pandas code to detect type(Request) and submit it using requests session in lieu of URL.
119- """
120- [{
121- 'from': 'aaa@aa.bb',
122- 'to': 'cc@dd.ee',
123- 'email_type': 'complaint',
124- 'sentiment': 'unhappy',
125- }]
126- """
127-
128- # Event hooks callback (eg log http status codes or other callback related functions)
121+ df = pd.read_csv( 'https://aa.com/bbb.csv', url_params=s)
122+
129123 def print_http_status(r, *args, **kwargs):
130124 print(r.status_code)
131125 print(r.headers['Content-Length'])
132126 s = Session()
133127 s.hooks = dict(response=print_http_status)
134- df = pd.read_csv( 'https://aa.com/bbb.csv', req_session =s)
128+ df = pd.read_csv( 'https://aa.com/bbb.csv', url_params =s)
135129
136130
137131
0 commit comments