Does anyone know what is wrong with my code?
import requests
import http.server
import socketserver
import threading
PORT = 8080
Handler = http.server.SimpleHTTPRequestHandler
# creates a server at url: http://locahost:8080
def create_server():
with socketserver.TCPServer(("", PORT), Handler) as httpd:
print("serving at port", PORT, flush=True)
httpd.serve_forever()
try:
thread = threading.Thread(target=create_server, args=())
thread.start()
r = requests.post('http://localhost:8080/get-data', data={'key': 'value'})
b = requests.get('http://localhost:8080/get-data')
print(b.json())
except:
print('starting the server was unsuccessful')
I have an index.html for the server, and the server part seems to be working fine, but when I try to post and get data, I get an errors
127.0.0.1 - - [24/Mar/2020 20:51:58] code 501, message Unsupported method ('POST')
127.0.0.1 - - [24/Mar/2020 20:51:58] "POST /get-data HTTP/1.1" 501 -
and
127.0.0.1 - - [24/Mar/2020 20:52:00] code 404, message File not found
127.0.0.1 - - [24/Mar/2020 20:52:00] "GET /get-data HTTP/1.1" 404 -
Edit: I figured it out, check my solution in comments