TAGS :Viewed: 6 - Published at: a few seconds ago

[ Server for testing OAuth2 callback ]

I need to run an HTTP Server in Python to handle a callback from a website which uses OAuth2. I did some search and found that SimpleHTTPServer or BaseHTTPServer is what I was looking for.

Which one should I use to only receive a code from a GET callback? So I just want the code to remain simple.

Answer 1

The simplest working example I found is in this project:


In particular: example/server.py

If you are using BaseHTTPRequestHandler and that is the only thing your server is handling your class might be as simple as:

from urlparse import urlparse,parse_qsl
class Handler(BaseHTTPRequestHandler):

    def do_GET(self):
        url = urlparse(self.path)
        code = parse_qsl(url.query)['code']