【发布时间】:2018-07-17 19:34:32
【问题描述】:
我的 python 脚本有问题。
我想在客户端连接到服务器时发送信息。
我有 9 个用于保存数据的列表:
PLATFORM = []
PLATFORM_RELEASE = []
PLATFORM_ARCH = []
USER_ACCOUNT = []
COMPUTER_ACCOUNT = []
COUNTRY = []
CITY = []
LATITUDE_LONGITUDE = []
ORG = []
在我的客户中:
URL = "http://ipinfo.io/json"
Response = urllib2.urlopen(URL)
Reading_data = json.load(Response)
COUNTRY = str(Reading_data['country'])
CITY = str(Reading_data['city'])
LATITUDE_LONGITUDE = str(Reading_data['loc'])
ORG = str(Reading_data['org'])
PLATFORM = platform.uname()[0]
PLATFORM_RELEASE = platform.uname()[2]
PLATFORM_ARCH = platform.uname()[4]
USER_ACCOUNT = os.getlogin()
COMPUTER_ACCOUNT = platform.uname()[1]
try:
server.send(str.encode(PLATFORM))
server.send(str.encode(PLATFORM_RELEASE))
server.send(str.encode(PLATFORM_ARCH))
server.send(str.encode(USER_ACCOUNT))
server.send(str.encode(COMPUTER_ACCOUNT))
server.send(str.encode(COUNTRY))
server.send(str.encode(CITY))
server.send(str.encode(LATITUDE_LONGITUDE))
server.send(str.encode(ORG))
print "sending complete"
except:
print "sending information error"
在我的服务器中:
try:
PLATFORM.append(Connection.recv(1024))
PLATFORM_RELEASE.append(Connection.recv(1024))
PLATFORM_ARCH.append(Connection.recv(1024))
USER_ACCOUNT.append(Connection.recv(1024))
COMPUTER_ACCOUNT.append(Connection.recv(1024))
COUNTRY.append(Connection.recv(1024))
CITY.append(Connection.recv(1024))
LATITUDE_LONGITUDE.append(Connection.recv(1024))
ORG.append(Connection.recv(1024))
return
except:
print "error"
我的服务器输出:
['Linux4.16.0-kali2-amd64x86_64']
['rootBobby']
['NLPenningsveer52.3922,4.6786AS13213 UK-2 Limited']
[]
[]
[]
[]
[]
[]
我需要这个输出:
['Linux']
['4.16.0-kali2-amd64']
['x86_64']
['root']
['Bobby']
['NL']
['Penningsveer']
['52.3922,4.6786']
['AS13213 UK-2 Limited']
我的问题是什么? 为什么会这样?
注意:我正在使用 VPN
谢谢
【问题讨论】:
-
因为您每次读取 1024 个字节。您发送的数据小于 1024 字节,因此您从下一次发送调用中获取数据。为什么不将所有信息作为 json 字符串发送?
标签: python list sockets data-structures