2

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.

Incerteza
  • 32,326
  • 47
  • 154
  • 261

1 Answers1

0

The simplest working example I found is in this project:

https://github.com/demianbrecht/sanction

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']
        ...
Jas
  • 327
  • 2
  • 9