Goal
Make request to http://example.com/page?
using requests.get()
Problem
The question mark ("?") is automatically stripped from the request if it is the last character in the URL (eg. http://example.com/page?1
and http://example.com/page?!
work, http://example.com/page?
does not)
Sample code
import requests
endpoint = "http://example.com/page?"
r = requests.get(endpoint)
print(r.url) # -> "http://example.com/page"
assert r.url == endpoint # Raises AssertionError
Question
Without modifying the library, is it possible to reach the intended endpoint? Both intended solutions (if such exist) and workarounds are welcome.
Thanks!
?
flag is used in URLs to separate the 'route' from the parameters, such ashttps://www.google.com/search?q=stack
. So if no params are passed in the request, it makes sense to ignore a trailing?
?
at the end really make a difference? As far as the endpoint being requested from the server, the?
is doing nothing. This is not a limit of therequests
library.requests
uses something to parse the URL with, and since the?
means nothing in this instance, it is removed.