I'm trying to create a 2 way communication socket in python. The socket will listen for connections from the client until it gets the data formatted in string like this: 'PHONENUMBER|STATUS'. I will need to split that and convert it to json which will be sent via http request to a web api. When the api receives, it will handle the request and then it will return a status in json format which I will convert to string to return it to the client as string. I would like to have a professional opinion about my code and any additional ideas to what I would like to achieve would be appreciated.
import socket import json import requests import httplib HOST= '127.0.0.1' PORT= 80 s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) #Bind to adress s.bind((HOST,PORT)) print ("Socket bound.") #Start listening s.listen(10) print ("Socket Listening") conn, addr = s.accept() url = 'http://www.google.com' while True: data = conn.recv(1024) dictionary = dict(item.split("|") for item in data .split(";")) json = json.dumps(dictionary, ensure_ascii=False) r = requests.get(url, data=json) print r.text