在python中通过自制TFTP发送访问对象
我正在尝试通过现有的 UDP 在 python 中创建 TFTP。在我的 server.py 中。
截至目前,我可以向服务器发送读取(RRQ)和写入(WRQ)请求。但是,然后数据包对象(创建的要发送到服务器的对象)到达服务器,我无法访问它。
在 server.py 中:
Packet = (server_from_client.recv())
print Packet
print id(Packet)
print Packet.opCode
这会产生以下输出:
('127.0.0.1', 53909)
recv done
<Packet.Packet object at 0x1e89f50>
42518000
Traceback (most recent call last):
File "servertest.py", line 16, in <module>
print Packet.opCode
AttributeError: 'str' object has no attribute 'opCode'
为什么它首先告诉我它是一个 Packet.Packet 对象(它有一个 opCode),然后说它是一个没有 opCode 的“str”对象???
任何帮助将不胜感激。
I'm trying to create a TFTP in python over a existing UDP i have. In my server.py.
As of now I'm able to send requests to read (RRQ) and write (WRQ) to the server. However, then a Packet object (Created object to be sent over to the server) reaches the server, I'm unable to access it.
In server.py :
Packet = (server_from_client.recv())
print Packet
print id(Packet)
print Packet.opCode
This produces this output :
('127.0.0.1', 53909)
recv done
<Packet.Packet object at 0x1e89f50>
42518000
Traceback (most recent call last):
File "servertest.py", line 16, in <module>
print Packet.opCode
AttributeError: 'str' object has no attribute 'opCode'
Why does it first tell me that it's a Packet.Packet object (which does have an opCode) and then say it's a 'str' object with no opCode ????
Any help will be appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的客户端不发送数据包,而是将其转换为字符串
)并通过线路发送。使用print type(Packet)
和print repr(Packet)
进行确认。Instead of sending the packet, your client side converts it to the string
<Packet.Packet object at 0x1e89f50>
and sends it over the wire. Useprint type(Packet)
andprint repr(Packet)
to confirm.