python request return 401 while the browser is works well - python-requests

I want to use the python request to access the below url, while I get the 401. while I can open the below url in the website. I don't know how to use the python request to access it.
https://data.10jqka.com.cn/funds/gnzjl/field/tradezdf/order/desc/page/2/ajax/1/free/1/
my code:
import requests
response = requests.get(url, headers=self.headers)
What I should do and could anyone give a code example to access that url?

Related

GET Request to the Notion Database API throwing 401 status code (using reqwest)

I'm working on a wasm rust app with Yew, and trying to retrieve database entries from Notion to fill the app's body content. I'm using reqwest to do all the http requesting part, but no matter what I do it keeps returning a 401 status code. I've tried the same reqwest both on postman and curl and it worked, so the bearer auth token and url should be correct.
Here's what the code looks like:
let client = reqwest::Client::new();
let request = client
.get(NOTION_URL)
.bearer_auth(NOTION_TOKEN)
.header("Notion-Version", NOTION_VERSION)
.fetch_mode_no_cors()
.build()
.unwrap();
let response = client.execute(request).await.unwrap();
I've tried logging NOTION_URL, NOTION_TOKEN, NOTION_VERSION env variables to be sure that they are correct, and they are.
I've tried different things, like adding additional headers like accept or user-agent but the result is the same. Also tried to set the client's default headers with both the notion version and auth headers without success.
My guess is that maybe the fetch_mode_no_cors() is the culprit, but without it the request doesn't even go through, and I can't find any alternative to this method.
I'm kinda lost tbh, don't know where to find a solution so here we go!
Thanks!

How does Postman send a file via HTTP?

I am really curious about how Postman sends a file via multipart/form-data HTTP request type.
I'm unable to track the algorithm that is used to compress the file, it won't show the complete request when trying to get the request code.
I'm interested in JavaScript/React (fetch) approach.
Any idea?
Thanks
It creates new FormData instance and appends upload as key and full path /home/light/Downloads/helixnebula.jpg to it as a value. Postman UI:

Axios post request in react-native app

I'm using axios in my react-native app, but I can't make any POST request in android simulator/device. It always return 400 Bad Request from the server.
I've tried to set Content-Type: application/json on headers but it didn't work as well.
on postman the request works as expected.
here's the request config object:
As you know, 400 Bad Request error means that the request you sent to the website server was somehow incorrect or corrupted and the server couldn't understand it.
I think there maybe problems on your request like as wrong URL or params or header format...
PS. Axios post methods syntax is as follows:
axios.post(url[, data[, config]])
You can test any axios method here and put it into your code base after it works.

Http Post Form request in Puppeteer chrome headless

I am doing some web scraping using puppeteer.
1.I need to use the post method to post a form and also specify the request header.
2.Download the response as pdf file.
I am not entirely sure how to write the syntax of Request and Response class of puppeteer.
Any suggestions?

400 Bad Request From users/show.json twitter request

I'm using Twitter OAuth provider to login to my site. This works great; I can login, and get the access token. I want to make an additional request to the server to grab some user information. Using the 1.1 API, I do:
var request = HttpWebRequest.Create("https://api.twitter.com/1.1/users/show.json?screen_name=name");
var response = request.GetResponse(); //400 bad request error
Again, I've successfully logged in, and at this point, I have not made any successful requests, so I'm not being rate limited. Any idea what my problem is?
I can make the previous API work fine, using the URL: http://api.twitter.com/1/users/show.json?screen_name=name. But not the new URL.
Thanks.
According to the Twitter Developers Documentation for response codes, you get a 400 in this case :
The request was invalid. An accompanying error message will explain
why. This is the status code will be returned during version 1.0 rate
limiting. In API v1.1, a request without authentication is considered
invalid and you will get this response.
Seeing your code (your URL is right and you use the 1.1 version of the API) I think that you forgot to authorize the request.

Resources