Basically, anything after a literal pound-sign in the URL is not sent to the server. This applies to browsers and requests
.
The format of your URL suggests that the type=#results
part is actually a query parameter.
requests
will automatically encode the query parameters, while the browser won't. Below are various queries and what the server receives in each case:
URL parameter in the browser
When using the pound-sign in the browser, anything after the pond-sign is not sent to the server:
https://httpbin.org/anything/type=#results
Returns:
{
"args": {},
"data": "",
"files": {},
"form": {},
"headers": {
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3",
"Accept-Encoding": "gzip, deflate, br",
"Accept-Language": "en-GB,en;q=0.9,en-US;q=0.8,de;q=0.7",
"Cache-Control": "max-age=0",
"Host": "httpbin.org",
"Upgrade-Insecure-Requests": "1",
"User-Agent": "*redacted*"
},
"json": null,
"method": "GET",
"origin": "*redacted*",
"url": "https://httpbin.org/anything/type="
}
- The URL received by the server is
https://httpbin.org/anything/type=
.
- The page being requested is called
type=
which does not seem to be correct.
Query parameter in the browser
The <key>=<value>
format suggest it might be a query parameter which you are passing. Still, anything after the pound-sign is not sent to the server:
https://httpbin.org/anything?type=#results
Returns:
{
"args": {
"type": ""
},
"data": "",
"files": {},
"form": {},
"headers": {
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3",
"Accept-Encoding": "gzip, deflate, br",
"Accept-Language": "en-GB,en;q=0.9,en-US;q=0.8,de;q=0.7",
"Host": "httpbin.org",
"Upgrade-Insecure-Requests": "1",
"User-Agent": "*redacted*"
},
"json": null,
"method": "GET",
"origin": "*redacted*",
"url": "https://httpbin.org/anything?type="
}
- The URL received by the server is
https://httpbin.org/anything?type=
.
- The page being requested is called
anything
.
- An argument
type
without a value is received.
Encoded query parameter in the browser
https://httpbin.org/anything?type=%23results
Returns:
{
"args": {
"type": "#results"
},
"data": "",
"files": {},
"form": {},
"headers": {
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3",
"Accept-Encoding": "gzip, deflate, br",
"Accept-Language": "en-GB,en;q=0.9,en-US;q=0.8,de;q=0.7",
"Host": "httpbin.org",
"Upgrade-Insecure-Requests": "1",
"User-Agent": "*redacted*"
},
"json": null,
"method": "GET",
"origin": "*redacted*",
"url": "https://httpbin.org/anything?type=%23results"
}
- The URL received by the server is
https://httpbin.org/anything?type=%23results
.
- The page being requested is called
anything
.
- An argument
type
with a value of #results
is received.
Python requests with URL parameter
requests
will also not send anything after the pound-sign to the server:
import requests
r = requests.get('https://httpbin.org/anything/type=#results')
print(r.url)
print(r.json())
Returns:
https://httpbin.org/anything/type=#results
{
"args": {},
"data": "",
"files": {},
"form": {},
"headers": {
"Accept": "*/*",
"Accept-Encoding": "gzip, deflate",
"Host": "httpbin.org",
"User-Agent": "python-requests/2.21.0"
},
"json": null,
"method": "GET",
"origin": "*redacted*",
"url": "https://httpbin.org/anything/type="
}
- The URL received by the server is
https://httpbin.org/anything?type=
.
- The page being requested is called
anything
.
- An argument
type
without a value is received.
Python requests with query parameter
requests
automatically encodes query parameters:
import requests
r = requests.get('https://httpbin.org/anything', params={'type': '#results'})
print(r.url)
print(r.json())
Returns:
https://httpbin.org/anything?type=%23results
{
"args": {
"type": "#results"
},
"data": "",
"files": {},
"form": {},
"headers": {
"Accept": "*/*",
"Accept-Encoding": "gzip, deflate",
"Host": "httpbin.org",
"User-Agent": "python-requests/2.21.0"
},
"json": null,
"method": "GET",
"origin": "*redacted*",
"url": "https://httpbin.org/anything?type=%23results"
}
- The URL received by the server is
https://httpbin.org/anything?type=%23results
.
- The page being requested is called
anything
.
- An argument
type
with a value of #results
is received.
Python requests with doubly-encoded query parameter
If you manually encode the query parameter and then pass it to requests
, it will encode the already encoded query parameter again:
import requests
r = requests.get('https://httpbin.org/anything', params={'type': '%23results'})
print(r.url)
print(r.json())
Returns:
https://httpbin.org/anything?type=%23results
{
"args": {
"type": "%23results"
},
"data": "",
"files": {},
"form": {},
"headers": {
"Accept": "*/*",
"Accept-Encoding": "gzip, deflate",
"Host": "httpbin.org",
"User-Agent": "python-requests/2.21.0"
},
"json": null,
"method": "GET",
"origin": "*redacted*",
"url": "https://httpbin.org/anything?type=%2523results"
}
- The URL received by the server is
https://httpbin.org/anything?type=%2523results
.
- The page being requested is called
anything
.
- An argument
type
with a value of %23results
is received.