简体   繁体   English

需要Python错误整数

[英]Python error integer is required

I'm trying to stress test my EC2 Micro instance using Python. 我正在尝试使用Python压力测试我的EC2 Micro实例。

I'm getting an error which seems self-explanatory but thats not the case: 我收到一个错误,它似乎是不言自明的,但事实并非如此:

Error: an integer is required 错误:必须为整数

stress_test function: Stress_test函数:

try:
    bytes = random._urandom(512)
    s = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
    s.connect((self.host, int(self.port)))
    s.setblocking(0)
    s.sendto(bytes, (self.host, self.port))
except Exception, e:
    print(str(e))

main function: 主功能:

  while True:
    if threading.activeCount() < thread_limit:
        stress_test(host_ip, host_port).start()

The error is on this line: s.sendto(bytes, (self.host, self.port)) 错误在此行上: s.sendto(bytes, (self.host, self.port))

However, If I try converting it to init I would of course get an invalid literal for int() with base 10 error. 但是,如果我尝试将其转换为init,我当然会invalid literal for int() with base 10得到一个invalid literal for int() with base 10错误的invalid literal for int() with base 10

I have also tried s.sendto(bytes(512), (self.host, self.port)) but then I get 'str' object is not callable error. 我也尝试过s.sendto(bytes(512), (self.host, self.port))但后来我得到'str' object is not callable错误。

What I'm I doing wrong? 我做错了什么?

self.port needs to be an integer; self.port必须为整数; use int(self.port) in the sendto line. 在sendto行中使用int(self.port)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM