I have been trying to connect to a remote server with python socket for that I am using create_connection but when my client tries to connect to that server it shown this error
AttributeError: 'socket' object has no attribute 'create_connection'
Here is my code
def _connect(self):
print("Connecting to ",self.hostname,self.port)
self.sock.create_connection((self.hostname, self.port))
print("Connection successfull")
Hostname and port is initialized in Constructor
def __init__(self, host, port, path, headers, method):
self.host = host.decode('utf-8')
self.hostname = socket.gethostbyname(self.host)
self.port = port
self.path = path.decode('utf-8')
self.header = headers
self.method = method.decode('utf-8')
self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
Host and port is parsed from urlparse library
def from_url(cls, url, header, method):
"""Construct a request for the specified URL."""
res = urlparse(url)
path = res.path
if res.query:
path += b'?' + res.query
return cls(res.hostname, res.port or 80, path, header, method)
self.sockequal to?