'Scrapy: Getting 403 Client Error from API post request
In body data, there are 3 null vale and I convert them into None and get ride of NameError: name 'null' is not defined but getting 403. How to solve the problem?
import scrapy
from scrapy.http import Request
import json
class OpenSeaSpider(scrapy.Spider):
name = 'opensea'
start_urls = ['https://opensea.io/rankings']
def parse(self, response):
api_url = 'https://api.opensea.io/graphql/'
headers = {
'Content-Type':'application/json',
'x-api-key':'2f6f419a083c46de9d83ce3dbe7db601',
'x-build-id': 'MlecpAI7Iur8bjb55hxna',
'x-signed-query': '89e599cadfd5ff7451e909df00286466a8fb1fec24566e7d22b0bf376779b7ca'
}
data = {"id":"RankingsPagePaginationQuery","query":"query RankingsPagePaginationQuery(\n $chain: [ChainScalar!]\n $count: Int\n $createdAfter: DateTime\n $cursor: String\n $parents: [CollectionSlug!]\n $sortBy: CollectionSort\n) {\n ...RankingsPage_data\n}\n\nfragment RankingsPage_data on Query {\n rankings(after: $cursor, chains: $chain, first: $count, sortBy: $sortBy, parents: $parents, createdAfter: $createdAfter) {\n edges {\n node {\n createdDate\n name\n slug\n logo\n isVerified\n floorPrice\n stats {\n marketCap\n numOwners\n totalSupply\n sevenDayChange\n sevenDayVolume\n oneDayChange\n oneDayVolume\n thirtyDayChange\n thirtyDayVolume\n totalVolume\n id\n }\n id\n __typename\n }\n cursor\n }\n pageInfo {\n endCursor\n hasNextPage\n }\n }\n}\n","variables":{"chain":null,"count":100,"createdAfter":null,"cursor":"YXJyYXljb25uZWN0aW9uOjk5","parents":null,"sortBy":"SEVEN_DAY_VOLUME"}}
return Request(
url=api_url,
method='POST',
headers=headers,
body=json.dumps(data),
callback=self.start
)
def start(self, response):
resp= json.loads(response.body)
print(resp)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
