Python socket TypeError: an integer is required (got type str)

tags: Python  notes  socket  tcp/ip  websocket  reptile  

Python Socket

TypeError: an integer is required (got type str)

Traceback (most recent call last):
  File "F:\py\demo.py", line 13, in <module>
    s.connect((host,port))
TypeError: an integer is required (got type str)

You can see that the Python prompts to connect, and the error isan integer is required (got type str)

Then I saw my code.

host=sys.argv[1]
port=sys.argv[2]	#        

s=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
s.connect((host,port))

It is only necessary to transfer the parameters passed by the port (port) to int. After the change is finished.

host=sys.argv[1]
port=int(sys.argv[2])	#        

s=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
s.connect((host,port))

problem solved.

Intelligent Recommendation

RandomResizedCrop error: TypeError: an integer is required (got type tuple)

Problem background The blogger’s version of pytorch is 0.4.1, and the version of torchvision is 0.2.1, an error occurs when the following code is executed. See the error below: Question inquiry ...

cv2.rectangle--TypeError: an integer is required (got type tuple)

Framed the face on the picture, the following error appeared: Haven't encountered it before, instackoverflowI found the explanation above, which is the reason why the image read by PIL.Image cannot us...

OpenCV [pit] TypeError: an integer is required (got type tuple)

It is really not easy to use OpenCV, always give you a surprise. If you are in the picture, your error is as follows: cv2.rectangle(src, (20, 20), (100, 100), (200, 0, 0), 1) TypeError: an integer is ...

Cv2.Rectangle error TYPEERROR: An Integer IS Required (Got Type Tuple)

Announcement TypeError: An Integer Is Required (Got Type Tuple) The above operation, will occupy too much memory, operate with np.stack ((IM_B, IM_G, IM_R), AXIS = 2)...

Pyspark: TypeError: An Integer is Required (got type bytes) resolved

Linux [Ubuntu, other versions are for reference only] Run the Pyspark program in Jupyter Notebook error, query information discovery, current2020.11.18Pyspark still does not support higher version of ...

More Recommendation

Python 3.5 Socket TypeError: a bytes-like object is required, not 'str' error

Original address: I am currently learning Python basic grammar and computer network lessons, so I just learned python network programming, see the third edition of "Python Core Programming",...

Python Socket TypeError: a bytes-like object is required, not 'str' error

"Python core programming," third edition, found Example 2-1 returns an error code that tangled for a long time ... .. Python2.7 find here python3.5 socket and return the decoded value are di...

python 3.5 Socket ——TypeError: a bytes-like object is required, not ‘str‘

STR can be compiled into the specified Byte by eNCode () Byte can be compiled into a specified STR through decode () There is an error in the Python network programming: TypeError: a bytes-like object...

The Python program generates a Windows executable / command window does not display / Can not generate exe error TypeError: an integer is required (got type bytes) Solution

Use pyinstaller Installation command: pip install pyinstaller or pip install https://github.com/pyinstaller/pyinstaller/archive/develop.tar.gz The second recommended: because I just started using the ...

Python - TypeError: unicode argument expected, got 'str'

reference:TypeError: unicode argument expected, got 'str' Python code: Interpreter error: Explanation of this question on stackoverflow is: io.StringIO is confusing in Python 2.7 because it's backport...

Copyright  DMCA © 2018-2026 - All Rights Reserved - www.programmersought.com  User Notice

Top