Skip to content

Python 3 compatibility issue when writing to stdout #113

@kazkansouh

Description

@kazkansouh

Hello,

I was just using this library and noticed when dumping to stdout by using the "-" option there is the following error:

[2020-09-11 08:16:42,305]     options -> {}                                                                                                                                            
[2020-09-11 08:16:42,317] Transferred 31 bytes                                                                                                                                         
[2020-09-11 08:16:42,318] Set remote port for session to 1136                                                                                                                          
[2020-09-11 08:16:42,318] Received DAT from server                                                                                                                                     
[2020-09-11 08:16:42,318] Handling DAT packet - block 1                    
[2020-09-11 08:16:42,318] Sending ack to block 1                                                                                                                                       
Traceback (most recent call last):        
  File "/root/.local/bin/tftpy_client.py", line 136, in <module>
    main()                                                                                                                                                                             
  File "/root/.local/bin/tftpy_client.py", line 120, in main 
    tclient.download(options.download,                                                     
  File "/root/.local/lib/python3.8/site-packages/tftpy/TftpClient.py", line 58, in download
    self.context.start()                                                                   
  File "/root/.local/lib/python3.8/site-packages/tftpy/TftpContexts.py", line 402, in start
    self.cycle()                                                                           
  File "/root/.local/lib/python3.8/site-packages/tftpy/TftpContexts.py", line 202, in cycle
    self.state = self.state.handle(recvpkt, raddress, rport)
  File "/root/.local/lib/python3.8/site-packages/tftpy/TftpStates.py", line 586, in handle                               
    return self.handleDat(pkt)                                                             
  File "/root/.local/lib/python3.8/site-packages/tftpy/TftpStates.py", line 182, in handleDat
    self.context.fileobj.write(pkt.data)                                                   
TypeError: write() argument must be str, not bytes

It appears to be caused by the following line

self.fileobj = sys.stdout

Probably it should be updated to:

self.fileobj = sys.stdout.buffer

I suspect the same issue applies to the input:

self.fileobj = sys.stdin

i.e. it should be updated to:

self.fileobj = sys.stdin.buffer

If you like, I can submit a PR to fix this?

Metadata

Metadata

Assignees

No one assigned

    Labels

    pendingNot looking at it yet

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions