TypeError: writable() takes 1 positional argument but 2 were given

16 Views Asked by At

I'm doing some udemy course and in one lesson there was an example with small and "easy" web application written in Python. Of course I retyped this code to my Visual studio code, but I'm receiving some errors.

My goal is to receive output in console when I'm refreshing my "web page" in the browser. I'm using this code on my own PC, so the URL which I'm using is: http://localhost:5000/ <--- and it is fine.

Actually, when I'm refreshing the web browser, I'm receiving this error:

----------------------------------------
127.0.0.1 - - [24/Oct/2022 20:37:55] "GET /favicon.ico HTTP/1.1" 200 -
----------------------------------------
Exception happened during processing of request from ('127.0.0.1', 52802)
Traceback (most recent call last):
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.8_3.8.2800.0_x64__qbz5n2kfra8p0\lib\socketserver.py", line 316, in _handle_request_noblock
    self.process_request(request, client_address)
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.8_3.8.2800.0_x64__qbz5n2kfra8p0\lib\socketserver.py", line 347, in process_request
    self.finish_request(request, client_address)
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.8_3.8.2800.0_x64__qbz5n2kfra8p0\lib\socketserver.py", line 360, in finish_request
    self.RequestHandlerClass(request, client_address, self)
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.8_3.8.2800.0_x64__qbz5n2kfra8p0\lib\socketserver.py", line 747, in __init__
    self.handle()
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.8_3.8.2800.0_x64__qbz5n2kfra8p0\lib\http\server.py", line 427, in handle
    self.handle_one_request()
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.8_3.8.2800.0_x64__qbz5n2kfra8p0\lib\http\server.py", line 415, in handle_one_request
    method()
  File "c:/Users/seroslaw/Documents/python/Prometheus/http_server_app.py", line 11, in do_GET
    self.wfile.writable(bytes("<html><head><title>First application</title></head><body style='color: #333; margin-top: 30px;'><center><h2>Welcome to our first prometheus-python application.</center></h2></body></html>","utf-8"))
TypeError: writable() takes 1 positional argument but 2 were given
----------------------------------------

My code which i retyped from the course:

from asyncio import Handle
import http.server


class HandleRequests(http.server.BaseHTTPRequestHandler):

    def do_GET(self):
        self.send_response(200)
        self.send_header("Content-type", "text/html")
        self.end_headers()
        self.wfile.writable(bytes("<html><head><title>First application</title></head><body style='color: #333; margin-top: 30px;'><center><h2>Welcome to our first prometheus-python application.</center></h2></body></html>","utf-8"))
        self.wfile.close

if __name__ == "__main__":
    server = http.server.HTTPServer(('localhost', 5000), HandleRequests)
    server.serve_forever()

Can You show me where I'm making a mistake ? For now, I'm very big newbie in coding, I just want to run this web application to learn next things from my course.

0

There are 0 best solutions below