I was having issues with CORS for my server, and I tried to include the "Access-Control-Allow-Origin". When I ran the code below, it expected another input argument, even though the documentation shows that it only needs 2.
#!/usr/bin/python
import socketserver
import socket
import http.server
import sys
Handler = http.server.SimpleHTTPRequestHandler
Port = 8005
localHost = socket.gethostname()
httpd = socketserver.TCPServer(("localhost", Port), Handler)
Handler.send_header("Access-Control-Allow-Origin", "*")
Handler.end_headers()
httpd.handle_request()
request = httpd.recv(1000000)
httpd.serve_forever()
When I run this, I get the following issue:
File "serverDP.py", line 29, in <module>
Handler.send_header("Access-Control-Allow-Origin", "*")
TypeError: send_header() missing 1 required positional argument: 'value'
I've tried code from here and Github, but haven't had any luck. Thanks for the help.
Edit
I added a class and it now looks like this:
class CORSRequestHandler(http.server.SimpleHTTPRequestHandler):
def send_my_headers(self):
print("This is working :/")
self.send_header("Access-Control-Allow-Origin", "*")
http.server.SimpleHTTPRequestHandler.end_headers(self)
def end_headers(self):
self.send_my_headers()
Handler = CORSRequestHandler
Handler.send_my_headers(Handler)
I still have the same issue. However I'm not exactly sure what I should pass into the "Handler.send_my_headers()" function