0

My code :

import http.client

h1 = http.client.HTTPConnection('127.0.0.1')
h1.request('GET', '/')

I tried with localhost instead of the IP too and it doesn't work also. I am sure my apache is running, as i tested from the browser.

Traceback (most recent call last):
  File "/home/kali/i1.py", line 4, in <module>
    h1.request('GET', '/')
  File "/usr/lib/python3.9/http/client.py", line 1279, in request
    self._send_request(method, url, body, headers, encode_chunked)                                                                                                             
  File "/usr/lib/python3.9/http/client.py", line 1325, in _send_request                                                                                                        
    self.endheaders(body, encode_chunked=encode_chunked)                                                                                                                       
  File "/usr/lib/python3.9/http/client.py", line 1274, in endheaders                                                                                                           
    self._send_output(message_body, encode_chunked=encode_chunked)                                                                                                             
  File "/usr/lib/python3.9/http/client.py", line 1034, in _send_output                                                                                                         
    self.send(msg)                                                                                                                                                             
  File "/usr/lib/python3.9/http/client.py", line 974, in send                                                                                                                  
    self.connect()                                                                                                                                                             
  File "/usr/lib/python3.9/http/client.py", line 945, in connect
    self.sock = self._create_connection(
  File "/usr/lib/python3.9/socket.py", line 844, in create_connection
    raise err
  File "/usr/lib/python3.9/socket.py", line 832, in create_connection
    sock.connect(sa)
Hackaholic
  • 19,069
  • 5
  • 54
  • 72
user2370139
  • 1,297
  • 1
  • 11
  • 13
  • You have the traceback but where is the actual exception? – Selcuk Nov 10 '21 at 02:33
  • what do you get if you use `127.0.0.1` in web browser? OR maybe server doesn't uses standard port `80` and then you need `127.0.0.1:port`. For example: secure HTTPS uses `443` - but it would rather need `HTTPSConnection` with char `S` in `HTTPS` – furas Nov 10 '21 at 13:28
  • It works fine in a browser and I made sure to write 127.0.0.1:80 in the url bar. The exception is http.client.RemoteDisconnected: Remote end closed connection without response. Anyway there are other librarires I could use, but it's weird this isn't working... – user2370139 Nov 11 '21 at 18:27

0 Answers0