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

Exception thrown in TrackerServer after announce #3

Closed
sreecodeslayer opened this Issue Oct 28, 2017 · 5 comments

Comments

Projects
None yet
2 participants
@sreecodeslayer
Copy link
Contributor

sreecodeslayer commented Oct 28, 2017

I started the server as told in the README,

from pybtracker import TrackerServer
import asyncio


loop = asyncio.get_event_loop()
tracker = TrackerServer(local_addr=('0.0.0.0',6881),loop=loop)
print(":: TrackerServer initiated ::\n\nStarting server ... ")
asyncio.ensure_future(tracker.start())

try:
	loop.run_forever()
except KeyboardInterrupt:
	loop.run_until_complete(tracker.stop())

But an error comes up when I add a torrent file and as soon as Deluge announces the torrent that uses this tracker 'udp://192.168.42.229:6881' [initially tried with 'udp://127.0.0.1:6881']
What am I doing wrong here 🤔

Here is the output and the error that follows

:: TrackerServer initiated ::
Starting server ... 
Exception in callback _SelectorDatagramTransport._read_ready()
handle: <Handle _SelectorDatagramTransport._read_ready()>
Traceback (most recent call last):
  File "/usr/lib/python3.5/asyncio/events.py", line 125, in _run
    self._callback(*self._args)
  File "/usr/lib/python3.5/asyncio/selector_events.py", line 1016, in _read_ready
    self._protocol.datagram_received(data, addr)
  File "/home/madboy/Projects/py3/lib/python3.5/site-packages/pybtracker/server.py", line 124, in datagram_received
    tid, data[16:])
  File "/home/madboy/Projects/py3/lib/python3.5/site-packages/pybtracker/server.py", line 58, in process_announce
    elif len(self.allowed_torrents) > 0 and ih not in self.allowed_torrents:
TypeError: object of type 'NoneType' has no len()

@stuaxo

This comment has been minimized.

Copy link

stuaxo commented Oct 28, 2017

As a really quick fix try changing the elif in server.py line 58 to

elif self.allowed_torrents and ih not in self.allowed_torrents:

@sreecodeslayer

This comment has been minimized.

Copy link
Contributor Author

sreecodeslayer commented Oct 28, 2017

Cool, doing so works.
This seems to be the way to validate the allowed_torrents field instead of checking its length? 🙂

@stuaxo

This comment has been minimized.

Copy link

stuaxo commented Oct 28, 2017

This will be Falsey if allowed_torrents is None or empty,
and Truethy if allowed_torrents contains anything.

@sreecodeslayer

This comment has been minimized.

Copy link
Contributor Author

sreecodeslayer commented Oct 29, 2017

Right, I went through the source and shouldn't this be more of a bug, since self.allowed_torrent is by default None, which would throw this error every time we keep it to default.

If we fix it as in the quick fix you pointed out, this won't come up right?
May I come up with the PR, or should I leave this here 🙂

@stuaxo

This comment has been minimized.

Copy link

stuaxo commented Oct 29, 2017

Sounds like a PR is the right way to go.

@elektito elektito closed this in 62325b0 May 17, 2018

elektito added a commit that referenced this issue May 17, 2018

Merge pull request #4 from sreecodeslayer/master
Modify how allowed_torrents is checked, Fixes #3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment