0

I am currently hitting an API with some Python code using the requests module where I open a session. The only way to hit some resources is to be authenticated so I create an auth tuple with the my username and password. The code to get an idea of what all is being done is below.

Class Requester():
    def __init__(self, auth, noverify, user, pass):
        self.auth = auth
        self.noverify = noverify
        self.session = requests.Session()
        if self.auth:
            self.session.auth = (user, pass)

    def post(self, ...):
        r = self.session.post(self.urlbase + endpoint, data=args, files=files, verify=False)

This works successfully for any endpoint I've used.

Now, I need to do the same in JS. I have tried hitting endpoints that don't require authentication with both JQuery AJAX requests and with fetch. Both seem to work fine. Unfortunately, I have been unable to hit any endpoints that require auth to work. I suspect that the Python Session object is doing something with that tuple that I don't understand. Is there a way to produce the same request via JS?

Sal Aslam
  • 9
  • 1
  • Does this answer your question? [Use basic authentication with jQuery and Ajax](https://stackoverflow.com/questions/5507234/use-basic-authentication-with-jquery-and-ajax) – sudden_appearance Dec 20 '22 at 18:04

0 Answers0