How do you send in python http/2 headers?

Nighcore2

Registered Member
Joined
Apr 30, 2019
Messages
69
Reaction score
4
Those
Code:
:method: GET
:scheme: https
:authority: server.url.com
:path: /login.php?

I tried with hyper but are sended bad and i get web requests rejected
Code:
import hashlib
import requests
import json
from tls_version import MyAdapter
import collections
from userdata import  UserData
import time
from random import randrange
from hyper.contrib import HTTP20Adapter


headers2 = [('Upgrade-Insecure-Requests', '1'),
        ('User-Agent', 'Mozilla/5.0 (Linux; Android 5.1.1; google Pixel 2 Build/LMY47I; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/74.0.3729.136 Mobile Safari/537.36'),
        ('Accept', 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3'),
        ('Accept-Encoding', 'gzip, deflate'),
        ('Accept-Language', 'es-ES,es;q=0.9,en-US;q=0.8,en;q=0.7'),

        ]
class post_calls():
        def start(self,headers_pass,body_pass,params,url,method):
            proxies = {
                'http': ip,
                'https': ip
            }
            body = str(body_pass)


            #send the POST request
            session = requests.session()
            session.mount('https://', MyAdapter())
            session.headers =  collections.OrderedDict(headers_pass)
            if method == 'get':
                q = 'https://' + server + '.' + host
                q = q.replace('.www.', '.')
                session.mount('https://', HTTP20Adapter())
                print('q='+q)
                response = session.get(url, proxies=proxies, params=params, verify=charlesproxy)





def login_world2(sid):

    a = post_calls()
    q ='https://'+server+'.'+ host+'/login.php?mobile&sid='+sid+'&2'
    q = q.replace('.www.','.')
    params = {}
    url = q
    body = '0'
    login = a.start(headers2,body,params,url,'get')
    return login

if __name__ == "__main__":
    login_get = login_world(sid)
    print(login_get)

they are sended like these
Code:
:method: GET
:scheme: https
:authority: server.url.com
:path: /login.php?mobile&sid=577f0967545d6acec94716d265dd4867fa4db4a446326ecde7486a97feede14702f4911438f4a4cd097677f0dd962786ef14b3f16f1184ee63a506155d522f53&2
upgrade-insecure-requests: 1
user-agent: Mozilla/5.0 (Linux; Android 5.1.1; google Pixel 2 Build/LMY47I; wv) AppleWebKit/537.36 (KHTML
user-agent: like Gecko) Version/4.0 Chrome/74.0.3729.136 Mobile Safari/537.36
accept: text/html
accept: application/xhtml+xml
accept: application/xml;q=0.9
accept: image/webp
accept: image/apng
accept: */*;q=0.8
accept: application/signed-exchange;v=b3
accept-encoding: gzip
accept-encoding: deflate
accept-language: es-ES
accept-language: es;q=0.9
accept-language: en-US;q=0.8
accept-language: en;q=0.7

and i need them like these, like in the original request are

Code:
:method: GET
:authority: server.url.com
:scheme: https
:path: /login.php?mobile&sid=2ea530a62cb63af6c14be116b7df86ad85cd77c9a11aa3c881b3a460e6c14fbd1fd8b79bd66c9782073705cdff25e890e65b5aeb852fde24c2d54a6e4ee49890&2
upgrade-insecure-requests: 1
user-agent: Mozilla/5.0 (Linux; Android 5.1.1; google Pixel 2 Build/LMY47I; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/74.0.3729.136 Mobile Safari/537.36
accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3
accept-encoding: gzip, deflate
accept-language: es-ES,es;q=0.9,en-US;q=0.8,en;q=0.7
 
Hi,

Your headers object is not built correctly. This is an example...

in your header creation, you have made a list with some string elements. requests module documentation says to do this with an object that looks like this...

difference is {} versus [].

Code:
{
    "Accept": "application/json",
    "Accept-Encoding": "gzip, deflate, br",
    "Accept-Language": "en-US,en;q=0.9",
    "Host": "httpbin.org",
    "Referer": "https://httpbin.org/",
    "User-Agent": "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.142 Safari/537.36"
  }

cheers
 
Hi,

Your headers object is not built correctly. This is an example...

in your header creation, you have made a list with some string elements. requests module documentation says to do this with an object that looks like this...

difference is {} versus [].

Code:
{
    "Accept": "application/json",
    "Accept-Encoding": "gzip, deflate, br",
    "Accept-Language": "en-US,en;q=0.9",
    "Host": "httpbin.org",
    "Referer": "https://httpbin.org/",
    "User-Agent": "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.142 Safari/537.36"
  }

cheers
Im passing a tuple to collections.Orederectdict, like thath i create a ordered dictionary.
 
Im passing a tuple to collections.Orederectdict, like thath i create a ordered dictionary.

I understand the syntax, but the structure of your object is the problem. PM me if you like and I'll walk it down for you.
 
Back
Top