本文整理匯總了Python中requests.models.PreparedRequest.prepare方法的典型用法代碼示例。如果您正苦於以下問題:Python PreparedRequest.prepare方法的具體用法?Python PreparedRequest.prepare怎麽用?Python PreparedRequest.prepare使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類requests.models.PreparedRequest
的用法示例。
在下文中一共展示了PreparedRequest.prepare方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_prepared_copy
# 需要導入模塊: from requests.models import PreparedRequest [as 別名]
# 或者: from requests.models.PreparedRequest import prepare [as 別名]
def test_prepared_copy(kwargs):
p = PreparedRequest()
if kwargs:
p.prepare(**kwargs)
copy = p.copy()
for attr in ('method', 'url', 'headers', '_cookies', 'body', 'hooks'):
assert getattr(p, attr) == getattr(copy, attr)
示例2: test_no_keep_alive_by_default
# 需要導入模塊: from requests.models import PreparedRequest [as 別名]
# 或者: from requests.models.PreparedRequest import prepare [as 別名]
def test_no_keep_alive_by_default(self):
p = PreparedRequest()
p.prepare(
method='GET',
url='http://www.example.com',
hooks=default_hooks()
)
assert 'Connection' not in p.headers
示例3: test_data_argument_accepts_tuples
# 需要導入模塊: from requests.models import PreparedRequest [as 別名]
# 或者: from requests.models.PreparedRequest import prepare [as 別名]
def test_data_argument_accepts_tuples(list_of_tuples):
"""
Ensure that the data argument will accept tuples of strings
and properly encode them.
"""
for data in list_of_tuples:
p = PreparedRequest()
p.prepare(method="GET", url="http://www.example.com", data=data, hooks=default_hooks())
assert p.body == urlencode(data)
示例4: test_prepared_request_no_cookies_copy
# 需要導入模塊: from requests.models import PreparedRequest [as 別名]
# 或者: from requests.models.PreparedRequest import prepare [as 別名]
def test_prepared_request_no_cookies_copy():
p = PreparedRequest()
p.prepare(
method='GET',
url='http://www.example.com',
data='foo=bar',
hooks=default_hooks()
)
assert_copy(p, p.copy())
示例5: test_data_argument_accepts_tuples
# 需要導入模塊: from requests.models import PreparedRequest [as 別名]
# 或者: from requests.models.PreparedRequest import prepare [as 別名]
def test_data_argument_accepts_tuples(data):
"""Ensure that the data argument will accept tuples of strings
and properly encode them.
"""
p = PreparedRequest()
p.prepare(
method='GET',
url='http://www.example.com',
data=data,
hooks=default_hooks()
)
assert p.body == urlencode(data)
示例6: prepare_request
# 需要導入模塊: from requests.models import PreparedRequest [as 別名]
# 或者: from requests.models.PreparedRequest import prepare [as 別名]
def prepare_request(self, request):
"""Constructs a :class:`PreparedRequest <PreparedRequest>` for
transmission and returns it. The :class:`PreparedRequest` has settings
merged from the :class:`Request <Request>` instance and those of the
:class:`Session`.
:param request: :class:`Request` instance to prepare with this
session's settings.
"""
cookies = request.cookies or {}
# Bootstrap CookieJar.
if not isinstance(cookies, cookielib.CookieJar):
cookies = cookiejar_from_dict(cookies)
# Merge with session cookies
merged_cookies = RequestsCookieJar()
merged_cookies.update(self.cookies)
merged_cookies.update(cookies)
# Set environment's basic authentication if not explicitly set.
auth = request.auth
if self.trust_env and not auth and not self.auth:
auth = get_netrc_auth(request.url)
p = PreparedRequest()
p.prepare(
method=request.method.upper(),
url=request.url,
files=request.files,
data=request.data,
json=request.json,
headers=merge_setting(request.headers, self.headers, dict_class=CaseInsensitiveDict),
params=merge_setting(request.params, self.params),
auth=merge_setting(auth, self.auth),
cookies=merged_cookies,
hooks=merge_hooks(request.hooks, self.hooks),
)
return p
示例7: test_prepared_request_complete_copy
# 需要導入模塊: from requests.models import PreparedRequest [as 別名]
# 或者: from requests.models.PreparedRequest import prepare [as 別名]
def test_prepared_request_complete_copy():
p = PreparedRequest()
p.prepare(method="GET", url="http://www.example.com", data="foo=bar", hooks=default_hooks(), cookies={"foo": "bar"})
assert_copy(p, p.copy())