I had a Python script that would automatically add tickets to your basket on https://tickets.liverpoolfc.com/PagesPublic/Home/home.aspx
Now the script won't work, yet the same request works fine in Postman.
The request section works like this:
addheaders = {'origin': "https://tickets.liverpoolfc.com",
'upgrade-insecure-requests': "1",
'content-type': "application/x-www-form-urlencoded",
'user-agent': "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.109 Safari/537.36",
'accept': "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8"}
body={'__VIEWSTATE':'/wEPDwUJMzkxOTk4MjAyD2QWAmYPZBYCZg9kFgICAw9kFgJmD2QWCAIDDw8WAh4HVmlzaWJsZWhkZAIHDw8WAh8AaGRkAhEPDxYCHwBoZGQCIQ9kFgICAQ9kFgICCQ9kFgQCHQ9kFgICAQ9kFgRmD2QWHAIBD2QWAgIBDxYCHgRUZXh0BRhTZWxlY3QgQnkgU3RhbmQgYW5kIEFyZWFkAgMPFgIfAWVkAgUPFgIfAQUNVGlja2V0IEZpbHRlcmQCBw8WAh8AZxYKAgEPFgIfAQUUV2hhdCBpcyB5b3VyIGJ1ZGdldD9kAgMPDxYCHwEFDU1pbmltdW0gUHJpY2VkZAIEEBAPFgYeDkRhdGFWYWx1ZUZpZWxkBQVQcmljZR4NRGF0YVRleHRGaWVsZAUFUHJpY2UeC18hRGF0YUJvdW5kZxYCHghvbmNoYW5nZQXJAWRvY3VtZW50LmdldEVsZW1lbnRCeUlkKCdTaXRlTWFzdGVyQm9keV9Db250ZW50UGxhY2VIb2xkZXIxX3VzY1NlYXRTZWxlY3Rpb25fdXNjU3RhbmRBbmRBcmVhU2VsZWN0aW9uX2hkZlNlbGVjdGVkTWluaW11bVByaWNlJykudmFsdWU9dGhpcy52YWx1ZTsgUmVEcmF3U3RhZGl1bShmYWxzZSwgdHJ1ZSwgZmFsc2UsIGZhbHNlLCBmYWxzZSwgZmFsc2UpOxAVAQfCozIyLjAwFQEF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JykudmFsdWUgPSBkb2N1bWVudC5nZXRFbGVtZW50QnlJZCgnYXJlYURyb3BEb3duTGlzdCcpLm9wdGlvbnNbMV0udmFsdWUgOw0KfQ0KfQ0KPC9zY3JpcHQ+ZAIBD2QWAgIBDxYCHwFlZAIgD2QWAgIEEBAPFgYfAgULUHJvZHVjdENvZGUfAwUSUHJvZHVjdERlc2NyaXB0aW9uHwRnZBAVAhNMSVZFUlBPT0wgViBXQVRGT1JEFExGQyBGT1VOREFUSU9OIEVWRU5UFQIGMThMSFdUBjE4TEdBQxQrAwJnZxYBAgFkZBgBBS5jdGwwMCRjdGwwMCR1c2NQZXJzb25hbGlzYXRpb25CYXJUb3AkTG9naW5WaWV3Dw9kAgFkHnzO56IhX/YZIlxUnOQWGCL0xwM=',
'ctl00$ctl00$SiteMasterBody$ContentPlaceHolder1$uscSeatSelection$btnBuy':'Buy',
'ctl00$ctl00$SiteMasterBody$ContentPlaceHolder1$uscSeatSelection$ddlGameSelection':'18LGAC',
'ctl00$ctl00$SiteMasterBody$ContentPlaceHolder1$uscSeatSelection$hdfSelectedSeats':'MSU-U9/82/0251#A',
'ctl00$ctl00$SiteMasterBody$ContentPlaceHolder1$uscSeatSelection$uscStandAndAreaSelection$hdfProductCode':'18LGAC',
'ctl00$ctl00$SiteMasterBody$ContentPlaceHolder1$uscSeatSelection$uscStandAndAreaSelection$hdfProductPriceBand':'A'}
body = urllib.urlencode(body)
addreq = requests.post('https://tickets.liverpoolfc.com/PagesPublic/ProductBrowse/VisualSeatSelection.aspx?campaign=&product=18LGAC&productIsHomeAsAway=N&productsubtype=HOME&stadium=AS&type=H', headers=addheaders, data=body, verify=True)
I recieve a 200 status code, but the ticket is not added to the basket, however if I send this request through Postman then the ticket is added to the basket.
Related
I'm using python and trying to read the metadata from a token on solscan.
I am looking for the name, image, etc from metadata.
I am currently using JSON request which seems to work (ie not fail), but it only returns me:
{"holder":0}
Process finished with exit code 0
I am doing several other requests to website, so I think my request is correct.
I tried looking at the documentation on https://public-api.solscan.io/docs and I believe I am requesting the correct info, but I dont get it.
Here is my current code:
import requests
headers = {
'accept': 'application/jsonParsed',
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.102 Safari/537.36'
}
params = (
('tokenAddress', 'EArf8AxBi44QxFVnSab9gZpXTxVGiAX2YCLokccr1UsW'),
)
response = requests.get('https://public-api.solscan.io/token/meta', headers=headers, params=params)
#response = requests.get('https://arweave.net/viPcoBnO9OjXvnzGMXGvqJ2BEgl25BMtqGaj-I1tkCM', headers=headers)
print(response.content.decode())
Any help appreciated!
This code sample works:
import requests
headers = {
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.102 Safari/537.36'
}
params = {
'address': 'EArf8AxBi44QxFVnSab9gZpXTxVGiAX2YCLokccr1UsW',
}
response = requests.get('https://api.solscan.io/account', headers=headers, params=params)
print(response.content.decode())
I use another URL and parameters in my sample: https://api.solscan.io/account used instead of https://public-api.solscan.io/token/meta and address param instead of tokenAddress.
I have written a Python script to check whether a website exists or not. Everything works fine, except when checking http://www.dhl.com - the request times out. I have tried both GET and HEAD methods. I used https://httpstatus.io/ and https://app.urlcheckr.com/ to check DHL website and the result is error. The DHL website DOES exist! Here is my code:
import requests
a ='http://www.dhl.com'
def check(url):
try:
header = {'User-Agent':'Mozilla/5.0 (X11; CrOS x86_64 8172.45.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.64 Safari/537.36'}
request = requests.head(url, headers = header , timeout = 60)
code = request.status_code
if code < 400:
return "Exist",str(code)
else:
return "Not exist", str(code)
except Exception as e:
return "Not Exist",str(type(e).__name__)
print(check(a))
How can I resolve this error?
Testing with curl shows you need a couple of other headers for that DHL site
import requests
url = 'http://www.dhl.com'
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.135 Safari/537.36',
'Accept-Encoding': 'gzip, deflate, br',
'Accept-Language': 'en-US,en;q=0.9,fil;q=0.8',
}
request = requests.head(url, headers=headers, timeout=60, allow_redirects=True)
print(request.status_code, request.reason)
print(request.history)
Without these headers, curl never gets a response.
I'm doing a GET request on POSTMAN. The request is just this URL https://www.google.com/search?q=pip+google-images&tbm=isch and I get a 853639 characters long response(Which is the response I want).
So I want to do the same thing with Python. I used the Postman's GENERATE CODE SNIPPETS and copied the code for Python Requests, I pasted it into my own python script and ran it.
But the response I got was only 22490 characters long(The response I don't want).
Why is it happening?
Python's code:
import requests
url = "https://www.google.com/search"
querystring = {"q":"pip google-images","tbm":"isch"}
headers = {
'cache-control': "no-cache",
'postman-token': "6b5e997f-6651-2178-1371-5d6a555984a7"
}
response = requests.request("GET", url, headers=headers, params=querystring)
print(response.text)
You need to set the User-Agent, e.g.
headers = {
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36'
}
Include this in your headers.
I'm trying to make a program that will connect on a website using this code:
import requests
url = "https://website/cours/login/index.php"
headers = {
"User-Agent": "Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.117 Mobile Safari/537.36"
}
brack = requests.post(url,headers = headers, data={"username":"e19****","password":"0****"})
content = brack.content
print(content)
the thing is that when im posting, nothing happens, like if I just did a GET. There's no error when I run (200 OK).
Depending on the API definition, a POST request may not return a content. Since you're getting a 200 response. Most probably there's a json object that was returned with your POST request.
Try this:
import requests
url = "https://website/cours/login/index.php"
headers = {
"User-Agent": "Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.117 Mobile Safari/537.36"
}
response = requests.post(url,headers=headers,
data={"username":"e19****","password":"0****"})
print(response.json())
Usually, if the POST request is expected to give a real-time/streaming ("instant") response to provide/return some data or content, then you might get an session/job ID where you can poll/fetch the completed job at a later time.
These tutorial might be helpful:
https://realpython.com/flask-connexion-rest-api/
https://rapidapi.com/blog/how-to-use-an-api-with-python/
https://www.w3schools.com/tags/ref_httpmethods.asp
I have a simple Get request I'd like to make using Python's Request library.
import requests
HEADERS = {'user-agent': ('Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_5)'
'AppleWebKit/537.36 (KHTML, like Gecko)'
'Chrome/45.0.2454.101 Safari/537.36'),
'referer': 'http://stats.nba.com/scores/'}
url = 'http://stats.nba.com/stats/playbyplayv2?EndPeriod=10&EndRange=55800&GameID=0021500281&RangeType=2&Season=2016-17&SeasonType=Regular+Season&StartPeriod=1&StartRange=0'
response = requests.get(url, timeout=5, headers=HEADERS)
However, when I make the requests.get call, I get the error requests.exceptions.ReadTimeout: HTTPConnectionPool(host='stats.nba.com', port=80): Read timed out. (read timeout=5). But I am able to copy/paste that url into my browser and view the resulting JSON. Why is requests not able to get the result?
Your HEADERS format is wrong. I tried with this code and it worked without any issues:
import requests
HEADERS = {
'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.87 Safari/537.36',
}
url = 'http://stats.nba.com/stats/playbyplayv2?EndPeriod=10&EndRange=55800&GameID=0021500281&RangeType=2&Season=2016-17&SeasonType=Regular+Season&StartPeriod=1&StartRange=0'
response = requests.get(url, timeout=5, headers=HEADERS)
print(response.text)