Skip to content

Add ability to modify user_agent #81

Description

@davejbur

I am having trouble using the library inside a firewall, as Python is denied access to the outside world.

It would be useful to add/modify the user_agent header in outgoing requests so as to overcome this.

I have forked and tried to modify the code but cannot work out how to test it; I just get the error:

    from . import LLUAPIRateLimitError
ImportError: attempted relative import with no known parent package

However the mods required would I think be very simple - in pylibrelinkup.py:

  1. Line 53 insert:
    user_agent: str | None
  1. (New) line 104 insert:
    def set_user_agent(self, user_agent: str):
        """ Sets user_agent for when there's a problem accessing the server """
        self.user_agent = user_agent        
  1. (New) line 123 insert:
        if self.user_agent:
            headers.update({"User-Agent": self.user_agent})

The usage would also be very simple; the user's script would simply need to have something like:

        client = PyLibreLinkUp(email=the_username, password=the_password, api_url = api_url.APIUrl.EU2)
        client.set_user_agent("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/150.0.0.0 Safari/537.36 Edg/150.0.0.0")

I would do a pull request for this, but, as I said, at present I can't see how to test it!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions