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

Fix error on downloading magnetlink #7851

Conversation

xoriole
Copy link
Contributor

@xoriole xoriole commented Jan 24, 2024

With PR #7842 merged, it raised a bug in creating TorrentDefNoMetainfo object while doing metainfo check. The metainfo check failed with the following stacktrace.

[tribler-gui PID:1197156] 2024-01-24 14:13:33,359 - ERROR <error_handler:100> ErrorHandler.core_error(): 'str' object has no attribute 'decode'
Traceback (most recent call last):
  File "/home/user/tribler/src/tribler/core/components/restapi/rest/rest_manager.py", line 53, in error_middleware
    response = await handler(request)
  File "/home/user/tribler/pyenv39/lib/python3.9/site-packages/aiohttp/web_middlewares.py", line 114, in impl
    return await handler(request)
  File "/home/user/tribler/src/tribler/core/components/libtorrent/restapi/torrentinfo_endpoint.py", line 131, in get_torrent_info
    metainfo = await self.download_manager.get_metainfo(infohash, timeout=60, hops=hops, url=uri)
  File "/home/user/tribler/src/tribler/core/components/libtorrent/download_manager/download_manager.py", line 520, in get_metainfo
    download = await self.start_download(tdef=tdef, config=dcfg, hidden=True, checkpoint_disabled=True)
  File "/home/user/tribler/src/tribler/core/components/libtorrent/download_manager/download_manager.py", line 653, in start_download
    atp = download.get_atp()
  File "/home/user/tribler/src/tribler/core/components/libtorrent/download_manager/download.py", line 200, in get_atp
    atp["name"] = self.tdef.get_name_as_unicode()
  File "/home/user/tribler/src/tribler/core/components/libtorrent/torrentdef.py", line 558, in get_name_as_unicode
    return self.get_name_utf8()
  File "/home/user/tribler/src/tribler/core/components/libtorrent/torrentdef.py", line 326, in get_name_utf8
    return escape_as_utf8(self.get_name(), self.get_encoding())
  File "/home/user/tribler/src/tribler/core/components/libtorrent/torrentdef.py", line 38, in escape_as_utf8
    return string.decode(encoding).encode('utf8').decode('utf8')
AttributeError: 'str' object has no attribute 'decode'

This PR addresses the issue.

The issue was caused by a bug on creating TorrentDefNoMetainfo
object. With the latest change, the name field is made binary.
This PR addresses the changes.
@@ -511,7 +511,7 @@ async def get_metainfo(self, infohash: bytes, timeout: float = 30, hops: Optiona
elif infohash in self.downloads:
download = self.downloads[infohash]
else:
tdef = TorrentDefNoMetainfo(infohash, 'metainfo request', url=url)
tdef = TorrentDefNoMetainfo(infohash, b'metainfo request', url=url)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the fix. The name field is expected to be bytes.

@xoriole xoriole marked this pull request as ready for review January 24, 2024 15:58
@xoriole xoriole requested review from a team and egbertbouman and removed request for a team January 24, 2024 15:58
@xoriole xoriole merged commit 2860330 into Tribler:main Jan 25, 2024
34 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants