This is the url I build in the code logic.
redirect_url = "%s?first_variable=%s&second_variable=%s"%(response_url,first_value,second_value)
The response URL is built using the following code
response_url = request.build_absolute_uri(reverse('workshop:ccavenue_payment_response'))
output of this response_url is
http://localhost:8000/workshop/ccavenue/payment-response/
This is the output URL(redirect url)
http://localhost:8000/workshop/ccavenue/payment-response/%07%07%07%07%07%07%07?first_variable=xxxxxxxxxxxxxxxxxxxxxxxxxx&second_variable=encrypted_data
How can I remove %07 from my url ?
Thank You in advance.
Is that what you are looking after?
payload = {'first_variable': first_value, 'second_variable': second_value}
r = requests.get(response_url, params=payload)
try with print(r.url)
Related
everyone.
I have following code:
url = "url"
headers = {'Content-type': 'application/json'}
bot = telebot.TeleBot('xxx')
#bot.message_handler(commands=['start'])
def start_message(message):
bot.send_message(message.chat.id, message.chat.id)
bot.send_message(message.chat.id, message.chat.username)
data = {"userId": "message.chat.username", "chatId": "message.chat.id"}
answer = requests.post(url, data=data, headers=headers)
print(answer)
Answer is 400.
But when I use Postman with raw JSON:
{"userId":"xxx", "chatId": "xxx"}
It gives me 200.
Can't understand the difference. Thank you.
Maybe problem with data. No?
data = {"userId": f"{message.chat.username}", "chatId": f"{message.chat.id}"}
instead of
data = {"userId": "message.chat.username", "chatId": "message.chat.id"}
For the postman, it already has a feature to generate code for any programming language you just need to click the code button and you will get the code.
you just click on the code button right side of the image
Use json parameter instead of data. Note, that they are not the same: Difference between data and json parameters in python requests package.
answer = requests.post(url, json=data, headers=headers)
This is what I have so far. I'm very new to this so point out if I'm doing anything wrong.
import requests
url = "https://9anime.to/user/watchlist"
payload = {
"username":"blahblahblah",
"password":"secretstringy"
# anything else?
}
with requests.Session() as s:
res = s.post(url, data=payload)
print(res.status_code)
You will need to inspect the form and see where the form is posting to in the action tag. In this case it is posting to user/ajax/login. Instead of requesting the watchlist URL you should post those details to the loginurl. Once you are logged in you can request your watchlist.
from lxml.html import fromstring
import requests
url = "https://9anime.to/user/watchlist"
loginurl = "https://9anime.to/user/ajax/login"
payload = {
"username":"someemail#gmail.com",
"password":"somepass"
}
with requests.Session() as s:
res = s.post(loginurl, data=payload)
print(res.content)
# b'{"success":true,"message":"Login successful"}'
res = s.get(url)
tree = fromstring(res.content)
elem = tree.cssselect("div.watchlist div.widget-body")[0]
print(elem.text_content())
# Your watch list is empty.
You would need to have knowledge (documentation of some form) on what that URL is expecting and how you are expected to interact with it. There is no way to know just given the information you have provided.
If you have some system that is able to interact with that URL already (e.g. your able to log in with your browser), then you could try to reverse-engineer what it is your browser is doing...
I've tried, but it's always wrong.
is there a solution? So here is the code I am using:
from urllib import request
url = "http://www.gutenberg.org/files/2554/2554.txt"
response = request.urlopen(url)
raw = response.read().decode('utf8')
type(raw)
this is an error that happened****
The url http://www.gutenberg.org/files/2554/2554.txt does not exist. Simply try pasting the url in your browser.
Try it with a valid url, your code works!
I'm trying to write a code to collect resumes from "indeed.com" website.
In order to download resumes from "indeed.com" you have to login with your account.
The problem with me is after posting data it shows me response [200] which indicates successful post but still fail to login.
Here is my code :
import requests
from bs4 import BeautifulSoup
from lxml import html
page = requests.get('https://secure.indeed.com/account/login')
soup = BeautifulSoup(page.content, 'html.parser')
row_text = soup.text
surftok = str(row_text[row_text.find('"surftok":')+11:row_text.find('","tmpl":')])
formtok = str(row_text[row_text.find('"tk":') + 6:row_text.find('","variation":')])
logintok = str(row_text[row_text.find('"loginTk":') + 11:row_text.find('","debugBarLink":')])
cfb = int(str(row_text[row_text.find('"cfb":')+6:row_text.find(',"pvr":')]))
pvr = int(str(row_text[row_text.find('"pvr":') + 6:row_text.find(',"obo":')]))
hl = str(row_text[row_text.find('"hl":') + 6:row_text.find('","co":')])
data = {
'action': 'login',
'__email': 'myEmail',
'__password': 'myPassword',
'remember': '1',
'hl': hl,
'cfb': cfb,
'pvr': pvr,
'form_tk': formtok,
'surftok': surftok,
'login_tk': logintok
}
response = requests.post("https://secure.indeed.com/", data=data)
print response
print 'myEmail' in response.text
It shows me response [200] but when I search for my email in the response page to make sure that login is successful, I don't find it. It seems that login failed for a reason that I don't know.
send headers as well in your post request, get the headers from response headers of your browser.
headers = {'user-agent': 'Chrome'}
response = requests.post("https://secure.indeed.com/",headers = headers, data=data)
Some websites uses JavaScript redirection. "indeed.com" is one of them. Unfortunately, python requests does not support JavaScript redirection. In such situations we may use selenium.
Hi I'm quite the python newbie. I'm currently trying to write a python script that logs into a website for me, and then opens up another page. But it doesn't work.
import requests
from requests import session
payload = {'username': 'xxx#gmail.com', 'password': 'xxxx'}
url = 'https://login.opendns.com'
with session() as c:
c.post(url, data=payload)
response = c.get('https://dashboard.opendns.com/stats/all/topdomains/today/')
print(response.headers)
print(response.text)
Can someone please help? I get these errors:
"InsecurePlatformWarning"
and then gives me the html of the login page itself. What am I doing wrong? :(
You're setting your response variable equal to the response of the get request, which is separate and different from your post request. Try this:
response = c.post(url, data=payload)
and comment out the line with the c.get() call.
If the output after that looks good, try setting up a callback hook for the post call.
Define this function before your with block:
def get_today(*args, **kwargs):
response = c.get('https://dashboard.opendns.com/stats/all/topdomains/today/')
print response.text
Then change your post call to this:
response = c.post(url, data=payload, hooks=dict(response=get_today))