Home > front end >  403 HTML Error Code when sending request to lexica.art using Python
403 HTML Error Code when sending request to lexica.art using Python

Time:10-29

I need to get all image prompts from the https://lexica.art/?q=history request, but the website returns 403 error code when I am trying to send a request.

I already tried to set User-Agent property, and copied all the request properties, but it still isn't working.

Here is my code:

import requests

url="https://lexica.art/api/trpc/prompts.infinitePrompts?batch=1&input={"0":{"json":{"text":"history","searchMode":"images","source":"search","cursor":250}}}"

headers = {
'Accept': 'text/html,application/xhtml xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8',
'Accept-Encoding': 'gzip, deflate, br',
'Accept-Language': 'en-US,en;q=0.5',
'Alt-Used': 'lexica.art',
'cache-control': 'max-age=0',
'Connection': 'keep-alive',
'Host': 'lexica.art',
'Sec-Fetch-Dest': 'document',
'Sec-Fetch-Mode': 'navigate',
'Sec-Fetch-Site': 'cross-site',
'TE': 'trailers',
'Upgrade-Insecure-Requests': '1',
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/106.0.0.0 Safari/537.36'
}

r=requests.get(url, headers=headers)
print(r.status_code)

CodePudding user response:

I used selenium library instead, everything is working fine

  • Related