requests.models.Request.prepare

Here are the examples of the python api requests.models.Request.prepare taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

1 Examples 7

Example 1

Project: flask-mwoauth Source File: __init__.py
    @staticmethod
    def _prepare_long_request(url, api_query):
        """ Use requests.Request and requests.PreparedRequest to produce the
            body (and boundary value) of a multipart/form-data; POST request as
            detailed in https://www.mediawiki.org/wiki/API:Edit#Large_texts
        """

        partlist = []
        for k, v in iteritems(api_query):
            if k in ('title', 'text', 'summary'):
                # title,  text and summary values in the request
                # should be utf-8 encoded

                part = (k,
                        (None, v.encode('utf-8'),
                         'text/plain; charset=UTF-8',
                         {'Content-Transfer-Encoding': '8bit'}
                         )
                        )
            else:
                part = (k, (None, v))
            partlist.append(part)

        return Request(url=url, files=partlist).prepare()