Nazime Lakehal
Nazime Lakehal

Reputation: 1782

python can't send post request image

I'm trying to decode a qr image from a website with python: https://zxing.org/w/decode.jspx And i don't know why my post requests fail and i don't get any response

import requests
url ="https://zxing.org/w/decode.jspx" 
session = requests.Session()
f = {'f':open("new.png","rb")} 
response = session.post(url,files = f)
f = open("page.html","w")
f.write(response.text)
f.close()
session.close()

Even when i do it with a get requests it still fail ... :/

url ="https://zxing.org/w/decode.jspx" 
session = requests.Session()
data = {'u':'https://www.qrstuff.com/images/default_qrcode.png'}
response = session.post(url,data = data)
f = open("page.html","w")
f.write(response.text)
f.close()
session.close()

maby because the website contain two forms ? ... Thanks for helping

Upvotes: 0

Views: 209

Answers (2)

Nazime Lakehal
Nazime Lakehal

Reputation: 1782

Well i just saw my mistake ... the web site is : https://zxing.org/w/decode.jspx but once you have a post or a get it'll be https://zxing.org/w/decode without ".jspx" so i just removed it and every thing worked well !!

Upvotes: 0

RaminNietzsche
RaminNietzsche

Reputation: 2791

You can do this:

import urllib

url ="https://zxing.org/w/decode?u=https://www.qrstuff.com/images/default_qrcode.png" 
response = urllib.urlopen(url)
f = open("page.html","w")
f.write(response.read())
f.close()

If you want to send url action == get and if you want to post data as a file, action == post. You can check it with Hackbar addons on Firefox

Upvotes: 1

Related Questions