Skip to content

Python2-ism in neg TELNET server #2929

Closed

Description

@MarcelRaad

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

Activity

  1. vszakats commented on Sep 2, 2018

    @vszakats
    Member

    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)
  2. bagder commented on Sep 3, 2018

    @bagder
    Member

    @MarcelRaad that fix good for you as well?

  3. MarcelRaad commented on Sep 4, 2018

    @MarcelRaad
    MemberAuthor

    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'
    
  4. added a commit that references this issue on Oct 2, 2018
    42d8445
  5. locked as resolved and limited conversation to collaborators on Jan 2, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions