Here are the examples of the python api werkzeug.Request.from_values taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
1 Examples
0
Example 1
Project: chronology Source File: client.py
def _send_with_auth(values, secret_key, url):
"""Send dictionary of JSON serializable `values` as a POST body to `url`
along with `auth_token` that's generated from `secret_key` and `values`
scheduler.auth.create_token expects a JSON serializable payload, so we send
a dictionary. On the receiving end of the POST request, the Flask view will
have access to a werkzeug.datastructures.ImmutableMultiDict. The easiest
and most surefire way to ensure that the payload sent to create_token will
be consistent on both ends is to generate an ImmutableMultiDict using the
werkzeug.Request.
"""
data = urllib.urlencode(values)
# Simulate a Flask request because that is what will be unpacked when the
# request is received on the other side
request = Request.from_values(
content_length=len(data),
input_stream=StringIO(data),
content_type='application/x-www-form-urlencoded',
method='POST')
# Add the auth_token, re-encode, and send
values['auth_token'] = create_token(secret_key, dict(request.form))
data = urllib.urlencode(values)
req = urllib2.Request(url, data)
response = urllib2.urlopen(req)
return json.loads(response.read())