Last active
December 16, 2015 17:19
-
-
Save aroberts/5469345 to your computer and use it in GitHub Desktop.
Example code snips highlight an issue with requests posting to a url
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
######################################## | |
# client.py | |
import requests | |
url = 'http://localhost:5000/' | |
requests.post(url) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
######################################## | |
# pip requirements | |
Werkzeug==0.8.3 | |
distribute==0.6.31 | |
emulaterest==0.1 | |
requests==1.2.0 | |
wsgiref==0.1.2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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