D
D
Drayvod2018-04-27 18:00:38
Python
Drayvod, 2018-04-27 18:00:38

How to write a request correctly?

There is a specific site that I need to send a request to using the requests library.
How to correctly pass these Heders

GET https://mysite.com/5?embed=1 HTTP/1.1
Host: site.com
Connection: keep-alive
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.117 Safari/537.36
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8
Referer: https://mysite.com
Accept-Encoding: gzip, deflate, br
Accept-Language: ru-RU,ru;q=0.9,en-US;q=0.8,en;q=0.7
Cookie: _ga=GA1.2.1169963389.1523803584; stel_web_auth=https%3A%2F%2Fweb.telegram.org%2F; stel_ssid=31dffdd3cd3dca265d_2963das1217952533; _gid=GA1.2.1199944186.1524831182

There is this code:
import requests
from fake_useragent import UserAgent




url = 'https://юрлсайта.ком'
r = requests.get(url, headers={'User-Agent': UserAgent().chrome})
print(r.text)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Elvis, 2018-04-27
@Dr_Elvis

import requests

url = "https://mysite.com/5"

querystring = {"embed":"1%20HTTP/1.1"}

headers = {
    'Host': "t.me",
    'Connection': "keep-alive",
    'Upgrade-Insecure-Requests': "1",
    'User-Agent': "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.117 Safari/537.36",
    'Accept': "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8",
    'Referer': "https://mysite.com",
    'Accept-Encoding': "gzip, deflate, br",
    'Accept-Language': "ru-RU,ru;q=0.9,en-US;q=0.8,en;q=0.7",
    'Cookie': "_ga=GA1.2.1169963389.1523803584; stel_web_auth=https%3A%2F%2Fweb.telegram.org%2F; stel_ssid=31dffdd3cd3dca265d_2963das1217952533; _gid=GA1.2.1199944186.1524831182",
    'Cache-Control': "no-cache",
    'Postman-Token': "930f1009-7e5f-436e-9b5f-da372e57ac8c"
    }

response = requests.request("GET", url, headers=headers, params=querystring)

print(response.text)

There is such a thing as Postman in which you can test requests. one of the tricks is generating code in a different way, including Python requests. I don’t advise you to directly take everything from there, but to understand how and what can help.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question