def
param_method_url():
pass
def
param_param():
pass
def
param_data():
pass
def
param_json():
requests.request(method
=
'POST'
,
url
=
'http://127.0.0.1:8000/test/'
,
json
=
{
'k1'
:
'v1'
,
'k2'
:
'水电费'
})
def
param_headers():
requests.request(method
=
'POST'
,
url
=
'http://127.0.0.1:8000/test/'
,
json
=
{
'k1'
:
'v1'
,
'k2'
:
'水电费'
},
headers
=
{
'Content-Type'
:
'application/x-www-form-urlencoded'
}
)
def
param_cookies():
requests.request(method
=
'POST'
,
url
=
'http://127.0.0.1:8000/test/'
,
data
=
{
'k1'
:
'v1'
,
'k2'
:
'v2'
},
cookies
=
{
'cook1'
:
'value1'
},
)
from
http.cookiejar
import
CookieJar
from
http.cookiejar
import
Cookie
obj
=
CookieJar()
obj.set_cookie(Cookie(version
=
0
, name
=
'c1'
, value
=
'v1'
, port
=
None
, domain
=
'
', path='
/
', secure
=
False
, expires
=
None
,
discard
=
True
, comment
=
None
, comment_url
=
None
, rest
=
{
'HttpOnly'
:
None
}, rfc2109
=
False
,
port_specified
=
False
, domain_specified
=
False
, domain_initial_dot
=
False
, path_specified
=
False
)
)
requests.request(method
=
'POST'
,
url
=
'http://127.0.0.1:8000/test/'
,
data
=
{
'k1'
:
'v1'
,
'k2'
:
'v2'
},
cookies
=
obj)
def
param_files():
pass
def
param_auth():
from
requests.auth
import
HTTPBasicAuth, HTTPDigestAuth
ret
=
requests.get(
'https://api.github.com/user'
, auth
=
HTTPBasicAuth(
'wupeiqi'
,
'sdfasdfasdf'
))
print
(ret.text)
def
param_timeout():
pass
def
param_allow_redirects():
ret
=
requests.get(
'http://127.0.0.1:8000/test/'
, allow_redirects
=
False
)
print
(ret.text)
def
param_proxies():
pass
def
param_stream():
ret
=
requests.get(
'http://127.0.0.1:8000/test/'
, stream
=
True
)
print
(ret.content)
ret.close()
def
requests_session():
import
requests
session
=
requests.Session()
i1
=
session.get(url
=
"http://dig.chouti.com/help/service"
)
i2
=
session.post(
url
=
"http://dig.chouti.com/login"
,
data
=
{
'phone'
:
"8615131255089"
,
'password'
:
"xxxxxx"
,
'oneMonth'
: ""
}
)
i3
=
session.post(
url
=
"http://dig.chouti.com/link/vote?linksId=8589623"
,
)
print
(i3.text)
参数示例代码