Skip to content

Instantly share code, notes, and snippets.

@aroberts
Last active December 16, 2015 17:19
Show Gist options
  • Save aroberts/5469345 to your computer and use it in GitHub Desktop.
Save aroberts/5469345 to your computer and use it in GitHub Desktop.
Example code snips highlight an issue with requests posting to a url
########################################
# client.py
import requests
url = 'http://localhost:5000/'
requests.post(url)
########################################
# pip requirements
Werkzeug==0.8.3
distribute==0.6.31
emulaterest==0.1
requests==1.2.0
wsgiref==0.1.2
# usage:
# run server with `python server.py`
# in another session, run client with `python client.py`
# examine stack trace on server side
########################################
# server.py
from werkzeug.wrappers import Response
class PostExample(object):
def dispatch_request(self, request):
return Response('Hello World!')
def wsgi_app(self, environ, start_response):
request = Request(environ)
response = self.dispatch_request(request)
return response(environ, start_response)
def __call__(self, environ, start_response):
return self.wsgi_app(environ, start_response)
if __name__ == '__main__':
from werkzeug.serving import run_simple
app = PostExample()
from emulaterest import EmulateRestMiddleware
app.wsgi_app = EmulateRestMiddleware(app.wsgi_app)
run_simple('127.0.0.1', 5000, app, use_debugger=True, use_reloader=True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment