How to keep url encoded characters in requests in Python - python

I want to create a POST request to a site like mydomain.com?character=%61 using Requests library.
But if I use requests.post(url) with url = 'mydomain.com?character=%61' then it sends a POST request to mydomain.com?character=a. How can I keep %61 in request instead of decoding it to a?
Thanks all!

Related

What does 'requests.head()' do in python requests?

import requests
send = requests.head('https://httpbin.org')
print(send.text)
What does 'requests.head()' do ? i get empty responses
A head request is a request used when you do not actually need the page content - just the status-code of your connection with the site or http-headers.

Python GET request to redirecting URL does not actually redirect me

I have an URL that redirects me to an other page, for example:
https://www.redirector.com/1
that redirects me to https://www.redirected.com/1
I am trying to fetch the second URL using python requests, I tried doing so using the following code:
import requests
rq = requests.get('https://www.redirector.com/1')
for re in rq.history:
print(re.url)
But that doesn't output anything...
Then I tried print the rq.history and turns out that was actually an empty list. Is there a way to get the https://www.redirected.com/1 URL besides using the history attribute?
You could view the headers of the response and see if there is a Location header (https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Location) and the response code is 3xx. This would be the "low" level approach

Send form data with requests in Python not working

I'm start learning python with requests library and i get facebook for example.
This is my code:
import requests
get_response = requests.get(url='https://www.facebook.com/login/identify?
ctx=recover')
post_data = {'email':'mycorrectemailaddress'}
post_response = requests.post(url="https://www.facebook.com/login/identify?ctx=recover/POST", data=post_data)
print(post_response.text)
And my script not going to the next page, i don't know where is my fault.
You didn't pass all the required data.
payload = {lsd:AVpg3ZvY
email:your#email.com
did_submit:Search
__user:0
__a:1
__dyn:7AzHK4GgN1t2u6XgmwCwRAKGzEy4S-C11xG12wAxu13wIwHx27QdwPG2iuUG4XzEa8uwh9UcU88lwIwHwJwnoCcxG48hwv9FovgeFUuzUhws82BxCqUkguy99UK
__af:iw
__req:5
__be:-1
__pc:PHASED:DEFAULT
__rev:2929740}
Sadly, I don't know what are these args. But you could parse it from a get requrest on the page or use selenium for the informations, and pass cookies to the requests module, and then make the post request.

Python: get json data from https url using sockets

I need to get some json data using API
import requests
url = 'https://example.com/api/some-info/'
response = requests.get(url)
print(response.text) # Here is JSON needeed
And everything fine, except I need to make such requests very often, and API provider says:
You'll be banned if you make more than 5 requests per second, so use
sockets
So, how can I make this work via sockets?
Big thx for advices.

how to send http request without urlencode?

I am doing a Scan work,and Need to send http requests without urlencode. The web application use $_SERVER['REQUEST_URI'](php) to get URL, and I must use "<" or ">" to do my scan work. But python requests will encode ">" to "%3E". Is there any way to send http request without urlencode(requests, urllib, urllib2), except sending http requests using socket?
Firstly, I use requests to do it:
import requests
requests.get("http://test.com/index.php?id=1 and 1>1")
But the truth url the requests get is: http://test.com/index.php?id=1 and 1%3E1
This question has confused me for days, I'll be very happy to get any solution from you, and thanks all.
You can pass string parameters using the params argument. Like this:
requests.get("http://test.com/index.php", params="id=1 and 1>1")

Categories

Resources