2016-11-17 5 views
0
import socket 
import time 
HOST = "192.168.x.x" 
PORT = 5454 
data = "Hello" 
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) 
s.connect(HOST,PORT) 
while True: 
    s.sendto(data(HOST,PORT)) 
    print "send" + data 
    time.sleep(1) 

ich einen Fehler wie diese gettting: Traceback (most recent call last): File "/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/runtime/wsgi.py", line 240, in Handle handler = _config_handle.add_wsgi_middleware(self._LoadHandler()) File "/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/runtime/wsgi.py", line 299, in _LoadHandler handler, path, err = LoadObject(self._handler) File "/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/runtime/wsgi.py", line 85, in LoadObject obj = __import__(path[0]) File "/base/data/home/apps/s~lyfe-playtm/20161117t121204.397114004363270281/main.py", line 24, in <module> s.connect(HOST,PORT) File "/base/data/home/runtimes/python27/python27_dist/lib/python2.7/socket.py", line 222, in meth return getattr(self._sock,name)(*args) File "/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/api/remote_socket/_remote_socket.py", line 752, in connect address_hostname_hint=_hostname_hint) File "/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/api/remote_socket/_remote_socket.py", line 590, in _CreateSocket address_hostname_hint) File "/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/api/remote_socket/_remote_socket.py", line 632, in _SetProtoFromAddr address, port = address ValueError: too many values to unpackValueerror: zu viele Werte entpacken, wenn Buchse mit

Ich versuche Buchse in Google App Engine zu verwenden. Dies ist der Code, den ich in meine main.py eingegeben habe. Wie werde ich diesen Fehler los?

+0

Sie zeigen nicht den Code an, der diesen Fehler verursacht. Aber es sieht so aus als wäre "Adresse" kein 2-Tupel. – AChampion

Antwort

1

Von 17.2. socket — Low-level networking interface:

Socket addresses are represented as follows: ... A pair (host, port) is used for the AF_INET address family, where host is a string representing either a hostname in Internet domain notation like 'daring.cwi.nl' or an IPv4 address like '100.50.200.5', and port is an integer.

und

socket.connect(address)

Connect to a remote socket at address. (The format of address depends on the address family — see above.)

Note 

This method has historically accepted a pair of parameters for AF_INET addresses instead of only a tuple. This was never intentional 

and is no longer available in Python 2.0 and later.

Was bedeutet, dass Sie

s.connect(HOST,PORT) 

mit

s.connect((HOST,PORT)) 
ändern sollte

Ähnlich unten Änderung

s.sendto(data(HOST,PORT)) 

mit

s.sendto(data, (HOST,PORT)) 

Randbemerkung: wenn s.sendto() die Steckdose sollte mit nicht (entweder fallen die s.connect() oder benutzen s.send() oder s.sendall()) angeschlossen werden:

socket.sendto(string, address) socket.sendto(string, flags, address)

Send data to the socket. The socket should not be connected to a remote socket, since the destination socket is specified by address. The optional flags argument has the same meaning as for recv() above. Return the number of bytes sent. (The format of address depends on the address family — see above.)

+0

Bekam es! Vielen Dank:) –

Verwandte Themen