F
F
First Second2020-09-21 08:25:28
Python
First Second, 2020-09-21 08:25:28

Requests get returns 403 response, python?

When trying to execute a get request to the site https://pixabay.com/ru/ returns 403 code. I can not understand why, I tried to forward all the headers, without success. I ask for help because new to programming, so do not blame me if that.

from urllib import request
import requests
from bs4 import BeautifulSoup

URL = 'https://pixabay.com/ru/images/search/%D1%86%D0%B2%D0%B5%D1%82%D1%8B/'
HEADERS = {
    'accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9',
    'accept-encoding': 'gzip, deflate, br',
    'accept-language': 'ru-RU,ru;q=0.9,en-US;q=0.8,en;q=0.7',
    'cache-control': 'max-age=0',
    'cookie': '__cfduid=d28635537f8c2bcab9a835e38a89907ee1600611002; lang=ru; anonymous_user_id=bd0ade28-6b12-484b-8244-ee110afac042; is_human=1; _ga=GA1.2.688714912.1600611004; _gid=GA1.2.1780831711.1600611004; client_width=1519; dwf_attribution_template_ads=True',
    'sec-fetch-dest': 'document',
    'sec-fetch-mode': 'navigate',
    'sec-fetch-site': 'none',
    'sec-fetch-user': '?1',
    'upgrade-insecure-requests': '1',
    'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.102 Safari/537.36'
}


def get_html(url, params=None):
    r = requests.get(URL, headers=HEADERS, params=params)
    html = r.text
    return r

print(get_html(URL))

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dimonchik, 2020-09-21
@dimonchik2013

Pixabay has an API,
but if anything, you start with Postman

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question