mirror of
https://github.com/kennethreitz/requests.git
synced 2026-06-05 22:50:18 +00:00
Merge branch 'develop'
This commit is contained in:
@@ -1,6 +1,12 @@
|
||||
History
|
||||
-------
|
||||
|
||||
0.8.1 (2011-11-15)
|
||||
++++++++++++++++++
|
||||
|
||||
* URL Request path fix
|
||||
* Proxy fix.
|
||||
* Timeouts fix.
|
||||
|
||||
0.8.0 (2011-11-13)
|
||||
++++++++++++++++++
|
||||
|
||||
+3
-3
@@ -95,13 +95,13 @@ Status Code Lookup
|
||||
::
|
||||
|
||||
>>> requests.codes['temporary_redirect']
|
||||
301
|
||||
307
|
||||
|
||||
>>> requests.codes.teapot
|
||||
416
|
||||
418
|
||||
|
||||
>>> requests.codes['\o/']
|
||||
416
|
||||
200
|
||||
|
||||
Cookies
|
||||
~~~~~~~
|
||||
|
||||
@@ -7,9 +7,6 @@ Requests is under active development, and contributions are more than welcome!
|
||||
What Needs to be Done
|
||||
---------------------
|
||||
|
||||
- OAuth Support (`#65 <https://github.com/kennethreitz/requests/issues/65>`_)
|
||||
- HTTP Cert Checking (`#30 <https://github.com/kennethreitz/requests/issues/30>`_)
|
||||
- Removal of Poster (`#68 <https://github.com/kennethreitz/requests/issues/68>`_)
|
||||
- Python 3.x Support (`#70 <https://github.com/kennethreitz/requests/issues/70>`_)
|
||||
- Kerberos Support (`#47 <https://github.com/kennethreitz/requests/issues/47>`_)
|
||||
- More Flexible Context Manager (`#69 <https://github.com/kennethreitz/requests/issues/69>`_)
|
||||
+1
-1
@@ -30,7 +30,7 @@ Things shouldn’t be this way. Not in Python.
|
||||
|
||||
See `the same code, without Requests <https://gist.github.com/973705>`_.
|
||||
|
||||
Requests allow you to send **HEAD**, **GET**, **POST**, **PUT**,
|
||||
Requests allows you to send **HEAD**, **GET**, **POST**, **PUT**,
|
||||
**PATCH**, and **DELETE** HTTP requests. You can add headers, form data,
|
||||
multipart files, and parameters with simple Python dictionaries, and access the
|
||||
response data in the same way. It's powered by :py:class:`httplib` and :py:class:`urllib3`, and it strives to be as elegant and approachable as possible.
|
||||
|
||||
@@ -71,7 +71,7 @@ You can override this default behavior with the ``prefetch`` parameter::
|
||||
Configuring Requests
|
||||
--------------------
|
||||
|
||||
Sometimes you may want to configure a request to customize it's behavior. To do
|
||||
Sometimes you may want to configure a request to customize its behavior. To do
|
||||
this, you can pass in a ``config`` dictionary to a request or session. See the :ref:`Configuration API Docs <configurations>` to learn more.
|
||||
|
||||
|
||||
|
||||
@@ -39,7 +39,8 @@ We can read the content of the server's response::
|
||||
>>> r.content
|
||||
'[{"repository":{"open_issues":0,"url":"https://github.com/...
|
||||
|
||||
Requests does its best to decode content from the server. Most unicode charsets, ``gzip``, and ``deflate`` encodings are all seamlessly decoded.
|
||||
Requests does its best to decode content from the server. Most unicode
|
||||
charsets, ``gzip``, and ``deflate`` encodings are all seamlessly decoded.
|
||||
|
||||
|
||||
Make a POST Request
|
||||
@@ -51,7 +52,8 @@ POST requests are equally simple::
|
||||
|
||||
|
||||
Typically, you want to send some form-encoded data — much like an HTML form.
|
||||
To do this, simply pass a dictionary to the `data` argument. Your dictionary of data will automatically be form-encoded when the request is made::
|
||||
To do this, simply pass a dictionary to the `data` argument. Your
|
||||
dictionary of data will automatically be form-encoded when the request is made::
|
||||
|
||||
>>> payload = {'key1': 'value1', 'key2': 'value2'}
|
||||
>>> r = requests.post("http://httpbin.org/post", data=payload)
|
||||
@@ -114,7 +116,7 @@ Requests makes it simple to upload Multipart-encoded files::
|
||||
{
|
||||
"origin": "179.13.100.4",
|
||||
"files": {
|
||||
"hmm": "<censored...binary...data>"
|
||||
"report.xls": "<censored...binary...data>"
|
||||
},
|
||||
"form": {},
|
||||
"url": "http://httpbin.org/post",
|
||||
@@ -236,6 +238,11 @@ Making requests with Basic Auth is extremely simple::
|
||||
>>> requests.get('https://api.github.com/user', auth=('user', 'pass'))
|
||||
<Response [200]>
|
||||
|
||||
OAuth Authentication
|
||||
--------------------
|
||||
|
||||
Miguel Araujo's `requests-oauth <http://pypi.python.org/pypi/requests-oauth>`_ project provides a simple interface for
|
||||
establishing OAuth connections. Documentation and examples can be found on the requests-oauth `git repository <https://github.com/maraujop/requests-oauth>`_.
|
||||
|
||||
Digest Authentication
|
||||
---------------------
|
||||
@@ -254,7 +261,7 @@ Requests will automatically perform location redirection while using impodotent
|
||||
|
||||
GitHub redirects all HTTP requests to HTTPS. Let's see what happens::
|
||||
|
||||
>>> r = request.get('http://github.com')
|
||||
>>> r = requests.get('http://github.com')
|
||||
>>> r.url
|
||||
'https://github.com/'
|
||||
>>> r.status_code
|
||||
@@ -268,7 +275,7 @@ The :class:`Response.history` list contains a list of the
|
||||
If you're using GET, HEAD, or OPTIONS, you can disable redirection
|
||||
handling with the ``disable_redirects`` parameter::
|
||||
|
||||
>>> r = request.get('http://github.com')
|
||||
>>> r = requests.get('http://github.com')
|
||||
>>> r.status_code
|
||||
301
|
||||
>>> r.history
|
||||
@@ -276,7 +283,7 @@ handling with the ``disable_redirects`` parameter::
|
||||
|
||||
If you're using POST, PUT, PATCH, *&c*, you can also explicitly enable redirection as well::
|
||||
|
||||
>>> r = request.post('http://github.com')
|
||||
>>> r = requests.post('http://github.com', allow_redirects=True)
|
||||
>>> r.url
|
||||
'https://github.com/'
|
||||
>>> r.history
|
||||
@@ -298,8 +305,6 @@ You can tell requests to stop waiting for a response after a given number of sec
|
||||
``timeout`` only effects the connection process itself, not the downloading of the respone body.
|
||||
|
||||
|
||||
Note
|
||||
|
||||
Errors and Exceptions
|
||||
---------------------
|
||||
|
||||
|
||||
@@ -15,8 +15,8 @@ requests
|
||||
"""
|
||||
|
||||
__title__ = 'requests'
|
||||
__version__ = '0.8.0'
|
||||
__build__ = 0x000800
|
||||
__version__ = '0.8.1'
|
||||
__build__ = 0x000801
|
||||
__author__ = 'Kenneth Reitz'
|
||||
__license__ = 'ISC'
|
||||
__copyright__ = 'Copyright 2011 Kenneth Reitz'
|
||||
|
||||
+41
-14
@@ -11,7 +11,7 @@ import urllib
|
||||
import zlib
|
||||
|
||||
from Cookie import SimpleCookie
|
||||
from urlparse import urlparse, urlunparse, urljoin
|
||||
from urlparse import urlparse, urlunparse, urljoin, urlsplit
|
||||
from datetime import datetime
|
||||
|
||||
from .auth import dispatch as auth_dispatch
|
||||
@@ -181,7 +181,7 @@ class Request(object):
|
||||
if is_error:
|
||||
response.error = resp
|
||||
|
||||
response.url = self._build_url()
|
||||
response.url = self.full_url
|
||||
|
||||
return response
|
||||
|
||||
@@ -239,7 +239,9 @@ class Request(object):
|
||||
cookies=cookies,
|
||||
redirect=True,
|
||||
config=self.config,
|
||||
_poolmanager=self._poolmanager
|
||||
timeout=self.timeout,
|
||||
_poolmanager=self._poolmanager,
|
||||
proxies = self.proxies,
|
||||
)
|
||||
|
||||
request.send()
|
||||
@@ -279,8 +281,8 @@ class Request(object):
|
||||
else:
|
||||
return data, data
|
||||
|
||||
|
||||
def _build_url(self):
|
||||
@property
|
||||
def full_url(self):
|
||||
"""Build the actual URL to use."""
|
||||
|
||||
if not self.url:
|
||||
@@ -298,15 +300,41 @@ class Request(object):
|
||||
path = path.encode('utf-8')
|
||||
|
||||
path = urllib.quote(urllib.unquote(path))
|
||||
self.url = str(urlunparse([ scheme, netloc, path, params, query, fragment ]))
|
||||
|
||||
url = str(urlunparse([ scheme, netloc, path, params, query, fragment ]))
|
||||
|
||||
if self._enc_params:
|
||||
if urlparse(self.url).query:
|
||||
return '%s&%s' % (self.url, self._enc_params)
|
||||
if urlparse(url).query:
|
||||
return '%s&%s' % (url, self._enc_params)
|
||||
else:
|
||||
return '%s?%s' % (self.url, self._enc_params)
|
||||
return '%s?%s' % (url, self._enc_params)
|
||||
else:
|
||||
return self.url
|
||||
return url
|
||||
|
||||
@property
|
||||
def path_url(self):
|
||||
"""Build the path URL to use."""
|
||||
|
||||
url = []
|
||||
|
||||
p = urlsplit(self.full_url)
|
||||
|
||||
# Proxies use full URLs.
|
||||
if p.scheme in self.proxies:
|
||||
return self.full_url
|
||||
|
||||
path = p.path
|
||||
if not path:
|
||||
path = '/'
|
||||
url.append(path)
|
||||
|
||||
query = p.query
|
||||
if query:
|
||||
url.append('?')
|
||||
url.append(query)
|
||||
|
||||
return ''.join(url)
|
||||
|
||||
|
||||
|
||||
def send(self, anyway=False, prefetch=False):
|
||||
@@ -327,7 +355,7 @@ class Request(object):
|
||||
))
|
||||
|
||||
# Build the URL
|
||||
url = self._build_url()
|
||||
url = self.full_url
|
||||
|
||||
# Nottin' on you.
|
||||
body = None
|
||||
@@ -376,7 +404,7 @@ class Request(object):
|
||||
proxy = self.proxies.get(_p.scheme)
|
||||
|
||||
if proxy:
|
||||
conn = poolmanager.proxy_from_url(url)
|
||||
conn = poolmanager.proxy_from_url(proxy)
|
||||
else:
|
||||
# Check to see if keep_alive is allowed.
|
||||
if self.config.get('keep_alive'):
|
||||
@@ -404,10 +432,9 @@ class Request(object):
|
||||
|
||||
try:
|
||||
# Send the request.
|
||||
|
||||
r = conn.urlopen(
|
||||
method=self.method,
|
||||
url=url,
|
||||
url=self.path_url,
|
||||
body=body,
|
||||
headers=self.headers,
|
||||
redirect=False,
|
||||
|
||||
Reference in New Issue
Block a user