This is a pre-production deployment of Warehouse, however changes made here WILL affect the production instance of PyPI.
Latest Version Dependencies status unknown Test status unknown Test coverage unknown
Project Description

A Python wrapper for the built-in urllib module. The API is compatible with the excellent Requests library, but omitting features such as sessions and support for keep-alive, all in a single module (but requires the six compatibility library).

Notrequests is intended for doing HTTP requests on Google App Engine where Requests has some disadvantages. It works on Python 2.7 and Python 3.4 and later.

The project is hosted on GitHub.

Installation

From PyPI:

$ pip install notrequests

Or download and run setup as normal:

$ curl -L -o notrequests.zip https://github.com/davidwtbuxton/notrequests/archive/master.zip
$ unzip notrequests.zip
$ cd notrequests-master
$ python setup.py install

Usage

Basic usage

Notrequests is compatible with the Requests API (or it tries to be).

>>> import notrequests
>>>
>>> response = notrequests.get('http://httpbin.org/get')
>>> response.status_code == notrequests.codes.ok
True

But it doesn’t do everything that Requests does. There’s no session support, no keep-alive support and it reads the entire response into memory.

The response body is available as a byte string or as unicode.

>>> response = notrequests.get('http://httpbin.org/encoding/utf8')
>>> response.headers['content-type']
'text/html; charset=utf-8'
>>> type(response.content)
<type 'str'>
>>> type(response.text)
<type 'unicode'>

Decoding to unicode relies on the server having sent a valid content-type header. This is different to Requests because Requests has smarts to sniff the encoding should the response not include a content-type header.

Notrequests uses urllib2 but behaves more like Requests. So it won’t throw an exception on 4xx and 5xx responses.

>>> response = notrequests.get('http://httpbin.org/status/404')
>>> response.status_code == notrequests.codes.not_found
True

You can also test for failure, or raise an exception.

>>> response = notrequests.get('http://httpbin.org/status/200')
>>> response.ok
True
>>> response.raise_for_status()
>>> response = notrequests.get('http://httpbin.org/status/404')
>>> response.ok
False
>>> response.raise_for_status()
Traceback (most recent call last):
  ...
notrequests.HTTPError: Error 404 for http://httpbin.org/status/404

Redirects

If you want to prevent Notrequests following a redirect response, you can use the allow_redirects keyword:

>>> url = 'http://httpbin.org/redirect/1'
>>> response = notrequests.get(url)
>>> response.status_code
200
>>> response = notrequests.get(url, allow_redirects=False)
>>> response.status_code
302

On Google App Engine, the X-Appengine-Inbound-Appid header will only be set if the sending application doesn’t allow redirects!

Authentication

You can do basic auth just like Requests (but not other authentication types):

>>> url = 'http://httpbin.org/basic-auth/alice/secret'
>>> response = notrequests.get(url)
>>> response.status_code
401
>>> response = notrequests.get(url, auth=('alice', 'secret'))
>>> response.status_code
200

JSON

And send and decode JSON:

>>> import pprint
>>> response = notrequests.put('http://httpbin.org/put', json={'foo': ['bar', 'baz']})
>>> data = response.json()
>>> pprint.pprint(data)
{u'args': {},
 u'data': u'{"foo": ["bar", "baz"]}',
 u'files': {},
 u'form': {},
 u'headers': {u'Accept-Encoding': u'identity',
              u'Content-Length': u'23',
              u'Content-Type': u'application/json',
              u'Host': u'httpbin.org',
              u'User-Agent': u'notrequests/0.1'},
 u'json': {u'foo': [u'bar', u'baz']},
 u'origin': u'10.10.10.1',
 u'url': u'http://httpbin.org/put'}

Uploading files

There’s also support for uploading files:

>>> import io
>>> fileobj = io.BytesIO('foo bar baz')
>>> response = notrequests.post('http://httpbin.org/post', files={'upload': fileobj})
>>> response.json()['files']
{u'upload': 'foo bar baz'}

As with Requests, the keys in the files dict are the form field input names and the values in the files dict can be a 2-tuple of file name with file object or byte string:

>>> files = {'upload': ('my-file.txt', b'Foo\nbar\nbaz.')}
>>> response = notrequests.post('http://httpbin.org/post', files=files)
>>> print response.request.data
--10.10.10.1.503.2717.1443987498.810.2
Content-Disposition: file; name="upload"; filename="my-file.txt"
Content-Type: text/plain

Foo
bar
baz.
--10.10.10.1.503.2717.1443987498.810.2--

Disabling SSL certificate checking

Use the verify keyword to disable SSL certificate checks. The default is verify=True, so Notrequests will raise ssl.CertificateError if the certificate does not match the server’s hostname.

>>> response = notrequests.get('https://swupdl.adobe.com', verify=False)

Notrequests does not support specifying alternate CA bundles.

API compatibility

These are some features of the Requests API that Notrequests has not implemented. It isn’t a complete list, and it would be nice to have better support.

  • Sessions
  • Response.history
  • Streaming uploads / downloads and iterating over data
  • Alternate names for status codes
  • Proxies

If there is a missing feature that you want to use on App Engine, please open an issue on GitHub.

Tests

Run the tests with tox.

By default the tests make requests to http://httpbin.org, but you can run a local instance which will speed things up.

$ pip install httpbin gunicorn
$ gunicorn --bind 127.0.0.1:8888 httpbin:app &
$ export NOTREQUESTS_TEST_URL="http://127.0.0.1:8888"
$ tox

Why not use Requests?

Google App Engine patches httplib in the standard library to use its urlfetch service, and restricts the sockets API to applications with billing enabled. Requests does not use httplib and uses sockets.

If you want to use the app identity service to authenticate connections between App Engine applications you have to use the urlfetch service, you cannot use Requests. Notrequests works on App Engine, using the urlfetch service, because it uses the standard library.

Release History

Release History

0.7

This version

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.6

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.5

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.4

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.3

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.2.1

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.2

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.1

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

Download Files

Download Files

TODO: Brief introduction on what you do with files - including link to relevant help section.

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
notrequests-0.7.tar.gz (9.4 kB) Copy SHA256 Checksum SHA256 Source Jul 6, 2016

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS HPE HPE Development Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting