I am trying to call a jsp from python script.
The response returns "Access denied". How can I fix this?
Please find the sample code below
import requests
WEBSITE = 'https://www1.nseindia.com/'
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36'
}
HIT_URL = WEBSITE+'products/dynaContent/equities/equities/symbolMapping.jsp'
payloads = {'dataType': 'priceVolumeDeliverable',
'symbol' : 'WIPRO',
'segmentLink' : '3',
'symbolCount' : '1',
'series' : 'ALL',
'fromDat' : '01-01-2023',
'toDate' : '02-05-2023'
}
response = requests.get(HIT_URL, data=payloads,headers=headers)
print(response.text)
Related
I'm trying to use a python script to access on a website
But it tells me CSRF verification failed. Request aborted. The python-requests code is as followed:
import requests
payload = {
'inUserName': 'NAN',
'inUserPass': 'NAN'
}
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like
Gecko) Chrome/103.0.0.0 Safari/537.36',
'From': 'https://pruebita.gob.pe/accounts/login/',
}
with requests.Session() as s:
p = s.post('https://pruebita.gob.pe/accounts/login/', data=payload, headers=headers)
print (p.text)
r = s.get('A protected web page url')
print (r.text)
I am new to python and trying to build a data scraper.
When trying to run:
schedule_data = requests.get('https://nsmmhl.goalline.ca/schedule.php?league_id=264&from_date=2019-09-12&to_date=2020-02-02')
I get:
<bound method Response.raise_for_status of <Response [403]>>
Can anybody tell me why? The link works fine.
Set the header attribute of the request
headers = {
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) '
'AppleWebKit/537.36 (KHTML, like Gecko) '
'Chrome/80.0.3987.149 Safari/537.36'
}
schedule_data = requests.get(
'https://nsmmhl.goalline.ca/schedule.php?league_id=264&from_date=2019-09-12&to_date=2020-02-02',
headers=headers
)
I tried to create program which will create account on this site: https://www.kostkuj.cz/register
My main problem is that i dont really know how it works, so i re-builded one project to my requirements.
I also tried sending requests with login data as parsed text:
email: "email#gmail.com"
plainPassword: {first: "pass1", second: "pass1"}
first: "pass1"
second: "pass1"
username: "username3"
But i dont know what i am doing wrong.
This is my whole code:
import requests
headers = {
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.132 Safari/537.36 OPR/63.0.3368.71'
}
register_data = {
{"username":"username3","email":"email#gmail.com","plainPassword":{"first":"pass1","second":"pass1"}}
}
with requests.Session() as s:
url = 'https://api.kostkuj.cz/register'
r = s.get(url, headers=headers)
r = s.post(url, data=register_data, headers=headers)
print(r.content)
I am getting error like:
Traceback (most recent call last):
File "C:\Users\jiris\Desktop\spamkostkuj.py", line 9, in <module>
{"username":"username3","email":"email#gmail.com","plainPassword":{"first":"pass1","second":"pass1"}}
TypeError: unhashable type: 'dict'
First thing headers needs ro in pair i.e. key value pair. In your case somthing like:
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.132 Safari/537.36 OPR/63.0.3368.71'
}
Secondly, your are sending data as dict of dict which is incorrect, instead send a dict, like:
register_data = {"username":"username3","email":"email#gmail.com","plainPassword":{"first":"pass1","second":"pass1"}}
Try this. Hopefully is should work for you.
Here you go:
r = s.post(url, json=register_data, headers=headers)
so ive been trying to figure out how to do the 'follow' thing using python codes on imvu.com, but it always returns the message "invalid arguments" error in $: failed reading: not a valid json value"
import requests
headers = {
"Origin": "https://secure.imvu.com/",
"Referer": "https://secure.imvu.com/next/av/Sammy165/",
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.109 Safari/537.36",
"X-IMVU-SAUCE": "" #removed sauce for account safety
}
url = "https://api.imvu.com/profile/profile-user-696969696/subscriptions"
data = {"id": "https://api.imvu.com/profile/profile-user-175389029"}
req = requests.post(url=url, headers=headers, data=data)
print(req.text)
Have you tried
requests.post(url=url, headers=headers, json=data)
?
You have to do json.dumps(data). See code below
import requests
import json
headers = {
"Origin": "https://secure.imvu.com/",
"Referer": "https://secure.imvu.com/next/av/Sammy165/",
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.109 Safari/537.36",
"X-IMVU-SAUCE": "" #removed sauce for account safety
}
url = "https://api.imvu.com/profile/profile-user-696969696/subscriptions"
data = {"id": "https://api.imvu.com/profile/profile-user-175389029"}
req = requests.post(url=url, headers=headers, data=json.dumps(data))
print(req.text)
Output:
{"status":"failure","error":"ERROR-GENERIC-001","message":"Permission Denied: You are not allowed to modify this subscription set."}
r = request.get(url='https://www.zomato.com')
It gives a time out error and python interpreter just does not respond . I have tried some other sites and it works for them , but for this site it does not . Why is that ?
Usually, provide a User-Agent header may help a lot when trying to get a web page, which makes it more like a browser visit:
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.116 Safari/537.36 Edge/15.15063'
}
r = requests.get('https://www.zomato.com', headers=headers)