giampaolo / pyftpdlib

Extremely fast and scalable Python FTP server library
MIT License
1.66k stars 266 forks source link

Unexpected type error. #545

Closed IamRichter closed 3 years ago

IamRichter commented 3 years ago

Hey, I found a small bug (maybe is not a bug, probably I did something wrong) where the server complains about the data type of a variable in 2 occasions. The first one:

File "/usr/local/lib/python3.7/dist-packages/pyftpdlib/servers.py", line 274, in handle_accepted
    if not self._accept_new_cons():
  File "/usr/local/lib/python3.7/dist-packages/pyftpdlib/servers.py", line 140, in _accept_new_cons
    return self._map_len() <= self.max_cons
TypeError: '<=' not supported between instances of 'int' and 'str'

I "fix" it by forcing the value to be a integer.

        return self._map_len() <= self.max_cons
        return self._map_len() <= int(self.max_cons)

Similarly it happen again in line 281:

File "/usr/local/lib/python3.7/dist-packages/pyftpdlib/servers.py", line 281, in handle_accepted
    if self.ip_map.count(ip) > self.max_cons_per_ip:
TypeError: '>' not supported between instances of 'int' and 'str'

And again, I "fix" it again by forcing it to be a integer

            if self.ip_map.count(ip) > self.max_cons_per_ip:
            if self.ip_map.count(ip) > int(self.max_cons_per_ip):

My use of pyftpdlib is not really crazy stuff. I just extended the DummyAuthorizer to create a SQL authentication, and I also extended FTPHandler to log the uploaded files in SQL.

giampaolo commented 3 years ago

That's probably because you did something like FTPServer.max_cons = "20" in your code. max_cons should be an integer.

IamRichter commented 3 years ago

That's probably because you did something like FTPServer.max_cons = "20" in your code. max_cons should be an integer.

You are absolutely correct. I complete forgot that at some point I decided to put max_cons inside a .ini file, and forgot that it would return a string. Sorry for waste your time, and thank you.

giampaolo commented 3 years ago

No problem. ;)