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

Python2-ism in neg TELNET server #2929

Closed
MarcelRaad opened this Issue Sep 2, 2018 · 3 comments

Comments

Projects
None yet
3 participants
@MarcelRaad
Member

MarcelRaad commented Sep 2, 2018

I did this

./runtests.pl 1452

I expected the following

Running the test. Instead, I got:

=== Start of file telnet_server.log
 2018-09-02 11:54:28,032 ERROR [NTEL] 'bytes' object has no attribute 'format'
 Traceback (most recent call last):
   File "C:/MinGW/msys/1.0/home/marci/curl/tests/negtelnetserver.py", line 343, in <module>
     rc = telnetserver(options)
   File "C:/MinGW/msys/1.0/home/marci/curl/tests/negtelnetserver.py", line 37, in telnetserver
     f.write(b"{0}".format(pid))
 AttributeError: 'bytes' object has no attribute 'format'
 2018-09-02 11:54:28,032 INFO  [NTEL] Returning 2
=== End of file telnet_server.log
test 1452 SKIPPED: failed starting neg TELNET server

negtelnetserver.py (added in 06a6feb) tries hard to support both Python 2 and 3, but b"{0}".format(pid) doesn't seem to work in Python 3.

curl/libcurl version

7.61.1-DEV

operating system

MSYS/MinGW with Python 3.6.6 on Windows 10

@MarcelRaad MarcelRaad added the tests label Sep 2, 2018

@vszakats

This comment has been minimized.

Member

vszakats commented Sep 2, 2018

This seems to fix it (as per isolated tests with 2.7.15 and 3.7.0):

diff --git a/tests/negtelnetserver.py b/tests/negtelnetserver.py
index 8cfd4093b..2ace8acd6 100755
--- a/tests/negtelnetserver.py
+++ b/tests/negtelnetserver.py
@@ -34,7 +34,7 @@ def telnetserver(options):
     if options.pidfile:
         pid = os.getpid()
         with open(options.pidfile, "w") as f:
-            f.write(b"{0}".format(pid))
+            f.write("{0}".format(pid))
 
     local_bind = (HOST, options.port)
     log.info("Listening on %s", local_bind)
@bagder

This comment has been minimized.

Member

bagder commented Sep 3, 2018

@MarcelRaad that fix good for you as well?

@MarcelRaad

This comment has been minimized.

Member

MarcelRaad commented Sep 4, 2018

Yes, that seems to work for me, thanks @vszakats !
Unfortunately, after that, get:

Exception happened during processing of request from ('127.0.0.1', 57321)
Traceback (most recent call last):
  File "c:\Program Files\Python36\lib\socketserver.py", line 317, in _handle_request_noblock
    self.process_request(request, client_address)
  File "c:\Program Files\Python36\lib\socketserver.py", line 348, in process_request
    self.finish_request(request, client_address)
  File "c:\Program Files\Python36\lib\socketserver.py", line 361, in finish_request
    self.RequestHandlerClass(request, client_address, self)
  File "c:\Program Files\Python36\lib\socketserver.py", line 696, in __init__
    self.handle()
  File "C:/MinGW/msys/1.0/home/marci/curl/tests/negtelnetserver.py", line 62, in handle
    neg.send_do("NEW_ENVIRON")
  File "C:/MinGW/msys/1.0/home/marci/curl/tests/negtelnetserver.py", line 209, in send_do
    self.send_iac([NegTokens.DO, NegOptions.to_val(option_str)])
  File "C:/MinGW/msys/1.0/home/marci/curl/tests/negtelnetserver.py", line 205, in send_iac
    self.send_message(message)
  File "C:/MinGW/msys/1.0/home/marci/curl/tests/negtelnetserver.py", line 196, in send_message
    packed_message = self.pack(message)
  File "C:/MinGW/msys/1.0/home/marci/curl/tests/negtelnetserver.py", line 200, in pack
    return struct.pack(b'{0}B'.format(len(arr)), *arr)
AttributeError: 'bytes' object has no attribute 'format'

And if I then patch line 200 (and possibly 135) in the same way, I get:

Exception happened during processing of request from ('127.0.0.1', 62476)
Traceback (most recent call last):
  File "c:\Program Files\Python36\lib\socketserver.py", line 317, in _handle_request_noblock
    self.process_request(request, client_address)
  File "c:\Program Files\Python36\lib\socketserver.py", line 348, in process_request
    self.finish_request(request, client_address)
  File "c:\Program Files\Python36\lib\socketserver.py", line 361, in finish_request
    self.RequestHandlerClass(request, client_address, self)
  File "c:\Program Files\Python36\lib\socketserver.py", line 721, in __init__
    self.handle()
  File "C:/MinGW/msys/1.0/home/marci/curl/tests/negtelnetserver.py", line 68, in handle
    data = neg.recv(1024)
  File "C:/MinGW/msys/1.0/home/marci/curl/tests/negtelnetserver.py", line 117, in recv
    byte_int = self.byte_to_int(byte)
  File "C:/MinGW/msys/1.0/home/marci/curl/tests/negtelnetserver.py", line 135, in byte_to_int
    return struct.unpack('B', byte)[0]
TypeError: a bytes-like object is required, not 'int'

infinnovation-dev pushed a commit to infinnovation-dev/curl that referenced this issue Oct 2, 2018

Colin Hogben
Fix curl#2929 - Python2-ism in neg TELNET server
Fix problems caused by differences in treatment of bytes objects
between python2 and python3.

@bagder bagder closed this in 3b4f243 Oct 4, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment