Python Requests -+ Fiddler - python-3.x

import requests
#This URL will behe URL that your login form points to with the "action" tag.
endpoint = 'http://212.62.32.199/PracenjeStatusa/en/posiljke.aspx'
authData = '__EVENTTARGET=&__EVENTARGUMENT=&__VIEWSTATE=%2FwEPDwUJLTcxMTY5NjU2ZGR7njOKaq1g11AmcZw9c9ihygJsEg%3D%3D&__VIEWSTATEGENERATOR=2E16548E&__EVENTVALIDATION=%2FwEWBALkmpXkCALNi8izBALAiqiFDgLLss2aAfJVg6RlCVcsmln07F4h1zZ2JNQk&Broj=RS481619407GB&cmdOk=Find'
header = {'Cache-Control': 'private', 'Content-Type': 'text/html; charset=utf-8', 'Server': 'Microsoft-IIS/7.0', 'X-AspNet-Version': '2.0.50727', 'X-Powered-By': 'ASP.NET', 'Date': 'Mon, 21 Jan 2019 21:48:14 GMT', 'Content-Length': '2606'}
response = requests.post(endpoint, data=authData, headers=header)
print(response.headers)
print(response.status_code)
So I'm trying to access tracking status on the local post office website, but after executing the code the headers are returned?

Related

Tableau: Unable to upload Data Source using REST. [NodeJS]

I am trying to upload a data source to my tableau site using the following code:
const request = require('request')
const fs = require('fs')
const options = {
url: 'https://prod-apnortheast-a.online.tableau.com/api/3.12/sites/578341b7-325c-4dda-be08-ff0b10c4b18c/datasources',
headers: {
Authorization: 'Bearer xxxxxxxxxxxxxx',
'Content-Type': 'application/xml;charset=UTF-8',
boundary: 'boundary-string'
},
body: `--boundary-string
Content-Disposition: name="request_payload"
Content-Type: text/xml
<tsRequest>
<datasource name="datasource-name"
description="datasource-description">
<connectionCredentials name="xxxx#abc.com"
password="xxxxxx"/>
<project id="96ec15ee-eef1-41ac-beda-1f03d9209305" />
</datasource>
</tsRequest>
--boundary-string
Content-Disposition: name="tableau_datasource"; filename="datasource-file-name"
Content-Type: application/octet-stream
This is the content of data source file.
Hello from Mayank
--boundary-string--`
}
function callback (error, response, body) {
if (error) {
console.log(error)
}
console.log( body, response.headers, response.statusCode)
}
request.post(options, callback)
But instead of a successful upload, I get the following error:
Response Body:
<?xml version='1.0' encoding='UTF-8'?><tsResponse xmlns="http://tableau.com/api" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://tableau.com/api http://tableau.com/api/ts-api-3.12.xsd"><error code="406000"><summary>Bad Request</summary><detail>Content type 'application/xml;charset=UTF-8' not supported</detail></error></tsResponse>
Response Headers:
{
'content-type': 'application/xml;charset=UTF-8',
date: 'Mon, 30 Aug 2021 08:17:57 GMT',
p3p: 'CP="NON"',
'referrer-policy': 'strict-origin-when-cross-origin',
server: 'Tableau',
'set-cookie': [
'hid=pdanaa-hap01; domain=.prod-apnortheast-a.online.tableau.com; path=/; HttpOnly; Secure; SameSite=None',
'AWSELB=05DBF7950E7E74D8AC3E3765F2EF65B6BB96F639EDB7A6D781435ACF3E27CEC2643898FB33239EFFBCA90E45D6EE0951AC6ECA4251ACA4E386D74627D58239403899B395F5F04C31144F69D44D5789C3FA7D6D9DC6;PATH=/;DOMAIN=.prod-apnortheast-a.online.tableau.com;SECURE;HTTPONLY;SAMESITE=None'
],
'strict-transport-security': 'max-age=31536000; includeSubDomains',
tableau_error_code: '0xE3C7443A',
tableau_error_source: 'NeedsClassification',
tableau_service_name: 'vizportal',
tableau_status_code: '2',
'x-content-type-options': 'nosniff',
'x-tableau': 'Tableau Server',
'x-ua-compatible': 'IE=Edge',
'x-xss-protection': '1; mode=block',
'content-length': '365',
connection: 'Close'
}
Response Status Code: 406
References:
https://help.tableau.com/current/api/rest_api/en-us/REST/rest_api_ref_publishing.htm#publish_data_source
https://help.tableau.com/current/api/rest_api/en-us/REST/rest_api_ref.htm
According to Tableau's documentation here
The Content-Type header for the request must be set to multipart/mixed; boundary=boundary-string.
Although I'm using PHP, I had this exact same error as you while trying to publish flows using the API. Changing to "multipart/mixed" in the Content-Type fixed it for me (wasn't the end of my problems though). So maybe changing your code to
...
headers: {
Authorization: 'Bearer xxxxxxxxxxxxxx',
'Content-Type': 'multipart/mixed; boundary=boundary-string'
},
...
could do the trick.
Please notice the content type change and that boundary is not a header by itself like you did.
Just note, your example code as it is might still generate 400 errors since that's not a valid data source file. Since I run Tableau Server I had to do a lot of troubleshooting by tailing the logs at the server and try to figure what was wrong.

How to get session id?

I'm doing a post request with axios
getSessionId() {
const endpoint = 'http://localhost:8069/web/session/authenticate/'
axios.post(endpoint, this.user).then((response) => {
this.cookie = response.headers
console.log(response.headers)
})
}
I know the session id is en headers as a cookie, In the terminal of vs code i got this
{
'content-type': 'application/json',
'content-length': '1355',
'access-control-allow-origin': '*',
'access-control-allow-methods': 'POST',
'set-cookie': [
'session_id=b459a3fe46e0b32b039b6ebded4db308472abbb4;
Expires=Thu, 04-Jun-2020 23:11:29 GMT; Max-Age=7776000;
HttpOnly; Path=/'
],
server: 'Werkzeug/0.16.0 Python/3.7.3',
date: 'Fri, 06 Mar 2020 23:11:29 GMT'
}
But when I console log the response of the browser its give me
{
content-length: "1355"
content-type: "application/json"
}

Clio API: bulk actions not returning 303 status code

I'm not seeing a 303 response for bulk actions using latest v4 api for the activities endpoint.
From The API Documentation:
Make a request to the action with an X-BULK header with the value true. The response will always be a 202 Accepted.
Poll the URL provided in the Location header of the response. This URL is for the Bulk Actions endpoint.
Once the action is complete, polling the URL will return a 303 See Other response.
Download the response from URL in the Location header of the 303 See other response.
Here's what I'm doing:
I issue the initial request to the activities endpoint with the X-BULK header set to 'true'.
I receive a 202 Acceptedresponse with a Location header set to the polling url.
I begin polling the provided url from the Location header.
I receive a few 200 responses with the following data and headers:
Data:
{"data":{"id":26952539,"etag":"\\"434fa52f83b8e0bb72677f60b8297866\\""}}
Headers:
{
'content-type': 'application/json; charset=utf-8',
'transfer-encoding': 'chunked',
connection: 'close',
vary: 'Accept-Encoding',
status: '200 OK',
'last-modified': 'Sat, 02 Dec 2017 22:17:13 GMT',
'x-ratelimit-limit': '50',
'x-ratelimit-reset': '1512253080',
'x-ratelimit-remaining': '45',
'x-request-id': '4674a764-c417-448c-af09-c6dae1cabe15',
etag: '"434fa52f83b8e0bb72677f60b8297866"',
'x-frame-options': 'SAMEORIGIN',
'cache-control': 'no-cache, private, no-store',
'x-xss-protection': '1; mode=block',
'x-api-version': '4.0.5',
'x-content-type-options': 'nosniff',
date: 'Sat, 02 Dec 2017 22:17:13 GMT',
'set-cookie':
[ 'XSRF-TOKEN=oQqTKV8XKRm9oiMuY1OFZ6qleZyRyvtcs9v52%2FWyeiVXxvVszHLiXsQkWelnUHs3ErSsH64ctIpehxErulAWHg%3D%3D; path=/; secure',
'_session_id=7babc5f94bc48ecd5d18d4b40c17d6ca; path=/; secure; HttpOnly' ],
server: 'nginx',
'strict-transport-security': 'max-age=31536000; includeSubdomains'
}
However a 303 never comes. After a few of the above 200s I get another 200 with the payload:
Data:
{
"data": [
{
"data": [ {id: 1...}, {id: 2...}, {id: 3...}, ... ],
"status": 200
}
],
"status": "completed",
"requested": 46,
"performed": 46
}
Headers:
{
'x-amz-id-2': '1uiNt20Vd/X74JxKZKrt/hah7aof8xfhZlt7fhlDt8b3G2nA47Y8ZDaohb2drSF8ErniirRK2Es=',
'x-amz-request-id': '2B29557952779E29',
date: 'Sat, 02 Dec 2017 22:17:15 GMT',
'last-modified': 'Sat, 02 Dec 2017 22:17:14 GMT',
'x-amz-expiration': 'expiry-date="Wed, 06 Dec 2017 00:00:00 GMT", rule-id="Expiration rule (auto-generated)"',
etag: '"58e33e4eced83d145bf6dec9f72b97be-1"',
'x-amz-server-side-encryption': 'AES256',
'content-encoding': 'utf-8',
'x-amz-version-id': '2Ou7F__59Pz8WKOKZwFg_fOuhQjD5ro0',
'content-disposition': 'attachment; filename="activities 20171202.json";',
'accept-ranges': 'bytes',
'content-type': 'application/json',
'content-length': '9593',
server: 'AmazonS3',
connection: 'close'
}
It appears I can work around this sufficiently by testing for status === 'completed', or even checking for the presence of the content-disposition header.
Am I doing something wrong that prohibits a 303 response, or are there semantics for the activities endpoint that I'm ignoring?
Is it sufficient to test for status === 'completed' to work around this issue?
Note: I am passing the Authorization header for every request, which includes the access token.
Thanks!
This is a known bug with the Clio API-V4.
The best solution at this time is:
testing the payload of the 200 for status === 'completed'
We are working on resolving the lack of 303 response. In the meantime we will update the documentation.
Here's a workaround I've been using with very good results:
Use the ignore_redirect parameter when querying a bulk action status:
/api/v4/bulk_actions/?ignore_redirect=true
Use the ?fields=Response_Url parameter to get the actual URL of the response.
Download the result from the Response_Url property.
I've never had these methods fail.

Node npm Unirest gives stale/old data

I am using Unirest middleware from inside my node js script to make a GET request. However for some reason I am getting stale/old data from the resource being requested.
Even after updating the data, I am getting stale data from the resource.
Here's the code :
let unirest = require('unirest');
unirest.get('<resource_url>')
.headers({"cache-control": "no-cache"})
.end(function (response) {
console.log('body===>',JSON.stringify(response.body));
console.log('status=====>',response.status);
console.log('response headers=====>',response.headers);
});
response headers=====> { 'strict-transport-security': 'max-age=15768000; includeSubDomains ',
date: 'Fri, 15 Sep 2017 18:58:40 GMT',
cached_response: 'true',
'cache-control': 'no-transform, max-age=3600',
expires: 'Fri, 15 Sep 2017 12:10:53 GMT',
vary: 'Accept,Accept-Encoding',
'content-length': '1383',
connection: 'close',
'content-type': 'application/json',
'content-language': 'en-US' }
The same resource gives updated data instantly when tried via Python scipt or CURL.
Note : After some time say 3hrs, the node js script gives updated data.

Node.js http.get request gets a totally different set of headers from a curl request

Okay I'm trying to get the headers of this specific URL and node.js behaviour baffles me.
My code :
var http = require('http');
var req = http.get("http://listen.radionomy.com/abc-lounge", function(res) {
console.log("headers: ", res.headers);
});
Prints out :
headers: { 'cache-control': 'private', 'content-type': 'text/html;
charset=utf-8', server: 'Microsoft-IIS/7.5', 'x-aspnet-version':
'4.0.30319', 'x-powered-by': 'ASP.NET', date: 'Tue, 28 Jan 2014
14:18:27 GMT', 'content-length': '8309' }
Now I tried out the command line curl with headers :
curl -I http://listen.radionomy.com/abc-lounge
This prints out exactly what I'm looking for (The redirect url) :
HTTP/1.1 302 Found Cache-Control: private Content-Length:
0 Content-Type: application/octet-stream Location:
http://streaming.radionomy.com/ABC-Lounge Server:
Microsoft-IIS/7.5 X-AspNetMvc-Version: 5.0 X-AspNet-Version:
4.0.30319 X-Powered-By: ASP.NET Date: Tue, 28 Jan 2014 14:19:20 GMT
I don't understand why node is getting a different set of headers. It should not follow redirects by default. I don't even think this is a redirect issue.
This is because http.get actually follows the redirect
I fake a curl request by adding some headers to your http.get like this:
var http = require('http');
var options = {
host: 'listen.radionomy.com',
path: '/abc-lounge',
headers: {
'user-agent': 'curl/7.31.0',
'accept': '*/*'
}
};
var req = http.get(options, function(res) {
console.log('status:', res.statusCode)
console.log("headers: ", res.headers);
});
Output will be:
status: 302
headers: { 'cache-control': 'private',
'content-type': 'application/octet-stream',
location: 'http://streaming.radionomy.com/ABC-Lounge',
server: 'Microsoft-IIS/7.5',
'x-aspnetmvc-version': '5.0',
'x-aspnet-version': '4.0.30319',
'x-powered-by': 'ASP.NET',
date: 'Tue, 28 Jan 2014 15:02:16 GMT',
'content-length': '0' }

Resources