@@ -86,52 +86,46 @@ Other Enhancements
86
86
87
87
If `python-requests` library is installed try to use it first. If not, continue using urllib
88
88
The :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
90
91
91
92
92
93
.. ipython:: python
93
94
import pandas as pd
94
- from requests import Session
95
95
96
- # req_session is optional parameter
96
+ # url_params is optional parameter
97
97
df = pd.read_csv('https://uname:
[email protected] /bb.csv') # now url can contain username and pwd
98
98
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()
101
109
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)
103
111
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
105
114
s = Session()
106
115
s.auth = ('darth', 'l0rd') # if user wants to perform basic auth Skip if url itself contains username and pwd
107
116
s.timeout = (3.05, 27) # if user wants to modify timeout
108
117
s.verify = False # if user wants to disable ssl cert verification
109
118
s.headers.update( {'User-Agent': 'Custom user agent'} ) # extensible to set any custom header needed
110
119
s.proxies = { 'http': 'http://a.com:100'} # if user has proxies
111
120
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:
[email protected] \nto:
[email protected] \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
-
122
-
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
+
129
123
def print_http_status(r, *args, **kwargs):
130
124
print(r.status_code)
131
125
print(r.headers['Content-Length'])
132
126
s = Session()
133
127
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)
135
129
136
130
137
131
0 commit comments