0

I'm making a CLI torrent searcher, but I'm having issues with extracting the location variable from the response header.

This is the relevant code:

if "1337x" in data[x]['source']:
    re = requests.get(f"https://{site}/{data[x]['magnet']}")
    magnet = re.headers[upper('location')]
subprocess.run(["xdg-open", magnet])

And this is the error message python gives me:

Traceback (most recent call last):
  File "/home/l/Projects/getTorrents/./torrentcli", line 35, in <module>
    re = requests.get(f"https://{site}/{data[x]['magnet']}")
  File "/usr/lib/python3.10/site-packages/requests/api.py", line 73, in get
    return request("get", url, params=params, **kwargs)
  File "/usr/lib/python3.10/site-packages/requests/api.py", line 59, in request
    return session.request(method=method, url=url, **kwargs)
  File "/usr/lib/python3.10/site-packages/requests/sessions.py", line 587, in request
    resp = self.send(prep, **send_kwargs)
  File "/usr/lib/python3.10/site-packages/requests/sessions.py", line 723, in send
    history = [resp for resp in gen]
  File "/usr/lib/python3.10/site-packages/requests/sessions.py", line 723, in <listcomp>
    history = [resp for resp in gen]
  File "/usr/lib/python3.10/site-packages/requests/sessions.py", line 266, in resolve_redirects
    resp = self.send(
  File "/usr/lib/python3.10/site-packages/requests/sessions.py", line 695, in send
    adapter = self.get_adapter(url=request.url)
  File "/usr/lib/python3.10/site-packages/requests/sessions.py", line 792, in get_adapter
    raise InvalidSchema(f"No connection adapters were found for {url!r}")
requests.exceptions.InvalidSchema: No connection adapters were found for 'magnet:?xt=foobar
utlthpjh
  • 41
  • 4
  • Welcome to Stack Overflow. Please start by *reading* the error message. Clearly, the problem is that *the request didn't succeed at all*, so there is no chance of getting headers from it. Since there is a problem accessing the URL, the next step is to check what URL was actually tried. The final error message looks suspicious, because it should show the entire URL, which should start with `https`. Maybe it has some strange control characters in it? – Karl Knechtel Aug 26 '22 at 23:45
  • The common solutions are at https://stackoverflow.com/questions/15115328/python-requests-no-connection-adapters but first we need to [debug](https://ericlippert.com/2014/03/05/how-to-debug-small-programs/) in order to check exactly what URL was provided. Please read [ask] and [mre]. – Karl Knechtel Aug 26 '22 at 23:47
  • Actually, since the error message uses `!r` formatting for the `url` that was passed, it shouldn't be possible for the error to be exactly as reported. Are you sure there aren't any more lines of output after this? The closing quote is missing, and if there *were* any control characters, they'd be escaped in the output. If you're hiding a tracker URL for privacy reasons, that's fine, but it's hard to say much without a [mre]. – Karl Knechtel Aug 26 '22 at 23:52

0 Answers0