首页 > 解决方案 > sock.bind() - TypeError: 需要一个整数

问题描述

我的 python 代码不接受字符串,而是需要整数,为什么?

sock.bind((UDP_IP,UDP_PORT)) Traceback(最近一次调用最后一次):文件“”,第 5 行,TypeError:需要一个整数(获取类型 str)

我的代码:

import socket
UDP_IP="localhost"
UDP_PORT="8080"
sock=socket.socket(socket.AF_INET,socket.SOCK_DGRAM)
sock.bind((UDP_IP,UDP_PORT))

标签: python-3.x

解决方案


推荐阅读