I made a program to open web pages using python 3.5 by using socket library. first, i prompt user to enter URL and then I split() that URL to extract host name for connect() method. But I am getting the following error which points towards my get request command:
cmd ='GET ' + user_url + ' HTTP/1.0\n\n'.encode() TypeError: Can't convert 'bytes' object to str implicitly
Following is my code:
import socket
user_url = input("Enter url: ")
host_name = user_url.split("/")[2]
mysock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
mysock.connect((host_name, 80))
cmd ='GET ' + user_url + ' HTTP/1.0\n\n'.encode()
mysock.send(cmd)
while True:
data = mysock.recv(512)
if (len(data) < 1):
break
print (data.decode(),end='')
mysock.close()
cmd =('GET ' + user_url + ' HTTP/1.0\n\n').encode()(cmd ='GET ' + user_url + ' HTTP/1.0\n\n').encode()?