response code acquired

This commit is contained in:
tonydero 2024-12-24 14:18:55 -07:00
parent 7de09b98ff
commit d5fe96c7cf

View File

@ -1,19 +1,17 @@
import requests import http.server
from http.server import *
import webbrowser
from oauthlib.oauth2 import WebApplicationClient from oauthlib.oauth2 import WebApplicationClient
import webbrowser
import re
import requests
class SavingRequestHandler(SimpleHTTPRequestHandler): class SavingRequestHandler(http.server.SimpleHTTPRequestHandler):
def do_GET(self): def do_GET(self):
print(self.path) SavingRequestHandler.response_path = self.path
def do_POST(self):
content_length = int(self.headers.get('Content-Length'))
print(self.rfile.read(content_length))
def wait_for_request(server_class=HTTPServer, def wait_for_request(server_class=http.server.HTTPServer,
handler_class=SavingHTTPRequestHandler): handler_class=SavingRequestHandler):
server_address = ('', 5635) server_address = ('', 5635)
httpd = server_class(server_address, handler_class) httpd = server_class(server_address, handler_class)
return httpd.handle_request() return httpd.handle_request()
@ -35,3 +33,5 @@ def authenticate():
wait_for_request() wait_for_request()
authenticate() authenticate()
response_code = re.search('code=(.*)&state=', SavingRequestHandler.response_path).group(1)
print("this is the way ->", response_code)