2016-11-17 11 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) 

を使用する際に解凍するためにあまりにも多くの値私はこのようなエラーを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 unpackとValueError:ソケット

私はGoogle App Engineのソケットを使用しようとしています。これは私がmain.pyに入れたコードです。どうすればこのエラーを取り除くことができますか?

+0

このエラーの原因となっているコードは表示されません。しかし、 'address'は2タプルではないようです。 – AChampion

答えて

1

17.2. socket — Low-level networking interfaceから:あなたは

s.connect((HOST,PORT)) 

s.connect(HOST,PORT) 

を変更する必要があります意味

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.

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.

s.sendto()を使用する場合、ソケットがないが接続されるべきである(s.connect()を落としたりs.send()又はs.sendall()を使用するか):

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

サイドノートと

同様に変化以下

s.sendto(data(HOST,PORT)) 

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

ありがとう:) –