Python - An HTTP Request in Python

Hello, I need help identifying what I´m doing wrong.

I´m trying to follow the lesson “HTTP Request in Python” by finding the file romeo.txt in VSCode using Python. I use the same code as the lesson

import socket
mysock = socket.socket((socket.AF_INET, socket.SOCK_STREAM))
mysock.connect(("", 80))
cmd = "GET HTTP/1.0\n\n".encode()

while True:
    data = mysock.recv(512)
    if(len(data) < 1):
    print(data.decode(), end="")

but I receive the following Traceback:

Traceback (most recent call last):
  File "c:\Users\Admin\Desktop\PY4E\fcc\", line 2, in <module>
    mysock = socket.socket((socket.AF_INET, socket.SOCK_STREAM))
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.2544.0_x64__qbz5n2kfra8p0\lib\", line 232, in __init__
    _socket.socket.__init__(self, family, type, proto, fileno)
TypeError: 'tuple' object cannot be interpreted as an integer

What am I doing wrong? If I run the progra, Ishould get back romeo.txt in my cli right?


The type error is coming from this line

mysock = socket.socket((socket.AF_INET, socket.SOCK_STREAM))

Should not be a tuple

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.