Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python 3 compatibility issue when writing to stdout #113

Open
kazkansouh opened this issue Sep 11, 2020 · 0 comments
Open

Python 3 compatibility issue when writing to stdout #113

kazkansouh opened this issue Sep 11, 2020 · 0 comments
Labels
pending Not looking at it yet

Comments

@kazkansouh
Copy link

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?

@kazkansouh kazkansouh changed the title Python 3 comparability issue when writing to stdout Python 3 compatibility issue when writing to stdout Sep 11, 2020
@msoulier msoulier added the pending Not looking at it yet label Nov 26, 2022
9001 added a commit to 9001/partftpy that referenced this issue Jun 16, 2024
again possible to upload from stdin, download to stdout
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pending Not looking at it yet
Projects
None yet
Development

No branches or pull requests

2 participants