[Python] Setting "self.client.headers" in a locust test by reading values from a config.txt...

Discussão em 'Python' iniciado por Stack, Janeiro 15, 2025.

  1. Stack

    Stack Membro Participativo

    I'm using configparser to read below values in a sample text file named config.txt:

    cookie='StaticWebAppsAuthCookie=GKeVpelA4wK+udvu7de737v7v8cv8v'
    Accept='*/*'
    Accept-Encoding=' gzip, deflate, br'
    Connection= 'keep-alive'`


    I'm reading the config.txt through below python code:

    config = configparser.ConfigParser()
    config.read('config.txt')
    self.client.headers = {'cookie': config.get('DEFAULT','cookie'),
    'Accept':config.get('DEFAULT','Accept'),
    'Accept-Encoding':config.get('DEFAULT','Accept-Encoding'),
    'Connection':config.get('DEFAULT','Connection')}'```

    I'm getting below error when executed:




    configparser.MissingSectionHeaderError: File contains no section headers.





    Kindly help in this, or suggest an alternate to achieve setting client-headers by reading values over a given .txt file

    Continue reading...

Compartilhe esta Página