Using Python Requests to maintain a session - python-3.x

I am trying to login to a website and based on the REST API guide provided, I will be able to receive some data for an application.
The two steps required for me to enact are:
1. Send a HTTP post command for authentication.
2. Send a GET command for receiving the data.
When I send the post command using python requests, i receive the required json response showing my login rights. e.g. role admin.
However, when I perform the get command after, it doesn't retrieve the data but sends an HTML form showing that I require authentication even though I have authenticated already.
Has anyone encountered this and how will I be able to solve it?
I am working on this for a customer and as a result, cannot post the actual login I am using and url and will hence replace this with my name with the code I will display.
Thanks
enter image description here

You can take a look at the session object in the requests library. It's used to keep a session across multiple requests.
https://3.python-requests.org/user/advanced/#session-objects
import requests
s = requests.Session()
s.get('http://httpbin.org/cookies/set?authcookie=123')
r = s.get('http://httpbin.org/cookies')
print(r.text)
This is a sample that uses a request session object to call a url that sets a cookie and then does another call with the same session (including the cookie). Just some basic example using http://httpbin.org/.

Related

How is the data from PassportJS used/gathered from the front end?

I've been looking into trying to get steam logins working with a small website project I'm making, and I've been looking through some resources but come to a similar roadblock(or rather a question) on how this is useful.
For example, in this article: https://medium.com/geekculture/sign-in-through-steam-using-nodejs-e3202d4719
They do all of the setup and such, and when the user logs in, it sends them to the steam login, and if successful, redirects them to the nodeJS port (ex: 3001) + api, in the article it is "localhost:XXXX/", but my question is: How does this get used on the actual website/frontend? How does the website know when to grab from this API? How does it know if the login was successful or not? Would it be a useEffect that checks the localhost:XXXX/ api every time the page loads to see if the api returned valid data or if it was just NULL data?

Make Python script open browser and execute HTTP post request

I want to send some HTTP POST requests to a website. There's no problem with doing it by my browser, since I'm logged in and I have my authenticated session.
I don't know how to make POST requests by Python while using that authenticated session (so importing data from the browser), and I don't even know if it's possibile, so I thought that I could trigger these POST requests in browser from the Python script.
I know there exists a library called "webbrowser" that allows to make requests by opening new tabs in browser. My problem is that I need a POST request, not a GET one.
So I ask you for 2 suggestions: is there a way to import authenticated session such that Pyhon can make requests for websites that require auth?
If not, is there a way of doing something like this:
webbrowser.open(url, new=0)
but with POST requests?
Thanks!
I agree with Mr. C, but alternatively...
Checkout Selenium. You can't make a direct POST request, but you can do anything that you would usually do as a normal user.
Check out the requests library. Seems like you need more functionality than the webbrowser module provides.

Benchmark Node.js Ghost with JMeter

I try to Benchmark Node.js Ghost with JMeter. I want to create a testplan which just signs in and then creates and publishes a post.
My problem now is that i do not get any session-cookies. So every request on the backend fails. I already tried to change the CookieManager settings within the user.properties file.
i tried following configuration:
CookieManager.check.cookies=false
CookieManager.delete_null_cookies=false
CookieManager.save.cookies=true
jmeter.save.saveservice.url=true
jmeter.save.saveservice.requestHeaders=true
This is the results tree (on the left side you can see my testplan setup):
I don't think Ghost uses cookies at all, the errors you're seeing are likely due to failed login.
Looking into response to the first request:
It seems Ghost uses OAuth authentication.
So you need to do the following:
Extract this access_token value from the /ghost/api/v0.1/authentication/token request response. You can do it using JSON Path PostProcessor like
Configure HTTP Header Manager for next requests to send Authorization header with the value of Bearer ${access_token}
The whole process of getting dynamic content from previous request, converting it to JMeter Variable and adding as a parameter to next request is known as correlation.

Method not allowed when trying to access API methods via SOAP integration

Good day,
I'm having trouble calling DSAPI methods via SOAP ( C# Integration ). I keep getting 405 Method not allowed errors. So far I've tried calling the RequestTemplate and CreateEnvelopeFromTemplates methods, both of which fail. I was able to successfully retrieve the DSAPIServiceSoapClient object and also successfully login via the login method of the credential API. If you need more information, i'm ready to provide them. Thank you.
You're succeeding with the login, which is good.
My guess is that the other calls are not well formed. Perhaps they're missing the right base url (which you receive from the login call).
Are you switching to the different base url for your subsequent calls? (Different server name?)
I suggest that you try the API logging feature and see what it reports. It enables you to see a log of your API requests. See the Request Logging article for the classic DocuSign experience, or the new DocuSign UI.
i just needed to add the in the X-DocuSign-Authentication http header whenever i try to get a DSAPIClient object.

Node.js Login using http post and get data after log in

How to do following actions using Node.js http POST, GET?
Log in to abc.com(It is a login page with login form)
In the page after log in, fill another form using POST and GET the result after posting the form.
Use the request module: https://www.npmjs.com/package/request. Inspect the login form, look at it's method and action, the using request send a request of the method type to the action with the needed form data. Then use the response's origin to see what the route of the next page is, and then POST to that route. You shouldn't need the GET then, it should respond with the result.
But instead of all this, if the site has supports oauth, you'd be much better off authenticating doing that with passport.js and using their api.

Resources