Downloading files to client with django and GCP - python

I'm trying to download a file from Django to client using GCP. Currently, the request is made from axios, the file is fetched from GCP using url from the model. This file is then downloaded and returned as a HTTP response to the client. Inside the network tab, I can see a 200 OK response and the image is visible in the preview. However, the download is not being saved to the client desktop. I would appreciate any suggestions
Download method:
def download(request, pk):
url = Model.objects.get(id=pk).__dict__["file1"]
storage_client = storage.Client()
bucket = storage_client.get_bucket(setting("GS_MEDIA_BUCKET_NAME"))
blob = storage.Blob(url, bucket)
filename = url.rsplit("/", 1)[1]
file_path = "temp/" + filename
file_to_download = open(file_path, "rb")
mime_type, _ = mimetypes.guess_type(file_path)
response = HttpResponse(file_to_download, content_type=mime_type)
response["Content-Disposition"] = "attachment; filename=%s" % filename
return response
Response headers
HTTP/1.1 200 OK
Date: Fri, 29 Oct 2021 08:01:15 GMT
Server: WSGIServer/0.2 CPython/3.9.7
Content-Type: image/jpeg
Content-Disposition: attachment; filename=default.jpg
Vary: Origin
Access-Control-Allow-Origin: http://localhost:3000
X-Frame-Options: SAMEORIGIN
Content-Length: 10994
X-Content-Type-Options: nosniff
Referrer-Policy: same-origin
Request headers
GET /api/models/download/26/ HTTP/1.1
Connection: keep-alive
sec-ch-ua: "Chromium";v="94", "Google Chrome";v="94", ";Not A
Brand";v="99"
Accept: application/json, text/plain, */*
sec-ch-ua-mobile: ?1
User-Agent: Mozilla/5.0 (Linux; Android 6.0; Nexus 5
Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko)
Chrome/94.0.4606.81 Mobile Safari/537.36
sec-ch-ua-platform: "Android"
Origin: http://localhost:3000
Sec-Fetch-Site: same-site
Sec-Fetch-Mode: cors
Sec-Fetch-Dest: empty
Accept-Encoding: gzip, deflate, br
Accept-Language: en-US,en;q=0.9

It's a sad day for axios and content-disposition https://medium.com/#drevets/you-cant-prompt-a-file-download-with-the-content-disposition-header-using-axios-xhr-sorry-56577aa706d6
The solution will be along the lines of the following code, from the front-end:
axios({
url: 'http://localhost:5000/static/example.pdf',
method: 'GET',
responseType: 'blob', // important
}).then((response) => {
const url = window.URL.createObjectURL(new Blob([response.data]));
const link = document.createElement('a');
link.href = url;
link.setAttribute('download', 'file.pdf');
document.body.appendChild(link);
link.click();
});

Related

How Send Cookie and Payload to Broker?

I need to send a buy request to my broker from c#.
when i send this request from google chrome, right click > inspect > network > Postdata give me this informations:
General
> Request URL: https://api2.mofidonline.com/Web/V1/Order/Post Request
> Method: POST Status Code: 200 Remote Address: 109.94.166.83:443
> Referrer Policy: strict-origin-when-cross-origin
Response Headers
access-control-allow-credentials: true
access-control-allow-origin: https://www.mofidonline.com
api-supported-versions: 1.0
content-encoding: gzip
content-type: application/json; charset=utf-8
date: Sat, 25 Sep 2021 20:46:10 GMT
set-cookie: TS0182ab0d=0180bb6f2279578c94b3b606e45b8e8836f5652f16390e58a9d78a748f534b2a9f44b16e8f6f38db6302791734e4522bb1cd199d2a; Path=/; Domain=.api2.mofidonline.com
vary: Accept-Encoding
vary: Origin
Request Headers
:authority: api2.mofidonline.com
:method: POST
:path: /Web/V1/Order/Post
:scheme: https
accept: */*
accept-encoding: gzip, deflate, br
accept-language: en-US,en;q=0.9,fa;q=0.8
authorization: BasicAuthentication ca4f8b23-2921-4f51-ab7c-ed9fcb04bb4d
content-length: 372
content-type: application/json
origin: https://www.mofidonline.com
referer: https://www.mofidonline.com/
sec-ch-ua: "Google Chrome";v="93", " Not;A Brand";v="99", "Chromium";v="93"
sec-ch-ua-mobile: ?0
sec-ch-ua-platform: "Windows"
sec-fetch-dest: empty
sec-fetch-mode: cors
sec-fetch-site: same-site
user-agent: Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/93.0.4577.82 Safari/537.36
Request Payload
{IsSymbolCautionAgreement: false, CautionAgreementSelected: false, IsSymbolSepahAgreement: false,…}
CautionAgreementSelected: false
FinancialProviderId: 1
IsSymbolCautionAgreement: false
IsSymbolSepahAgreement: false
SepahAgreementSelected: false
isin: "IRT1PLSH0001"
maxShow: 0
minimumQuantity: 0
orderCount: 1000
orderId: 0
orderPrice: 82870
orderSide: 65
orderValidity: 74
orderValiditydate: null
shortSellIncentivePercent: 0
shortSellIsEnabled: false
how can i send this information manual with httpwebrequest ( or any way other)? Please help me...

Python Requests post error response in chat system

I want to chat and send a photo on a system by python automatically. but give me the following error. Can you show me how to fix it?
the way I do is by Python Requests post () Method
imformation for files Request URL
Request URL: https://11.chat.com/file-api/v2/teams/123/rooms/123/attachment/files
Request Method: POST
Status Code: 200
Remote Address: 11.111.11.11:11
Referrer Policy: strict-origin-when-cross-origin
access-control-allow-origin: *
access-control-expose-headers: Accept-Ranges,Content-Encoding,Content-Length,Content-Range
content-encoding: gzip
content-type: application/json; charset=utf-8
date: Mon, 11 Apr 2020 1:36:05 GMT
chat-correlationid: 123-a0c0-11eb-ba75-bbcbc762f736
server: nginx/1.19.0 (Ubuntu)
vary: Accept-Encoding
x-powered-by: Express
:authority: 11.chat.com
:method: POST
:path: /file-api/v2/teams/123/rooms/123/attachment/files
:scheme: https
accept: application/vnd.tosslab.chat-v2+json
accept-encoding: gzip, deflate, br
accept-language: ja,en-US;q=0.9,en;q=0.8,es;q=0.7
authorization: bearer c12a8c2c975a23f73141320f6ad0fab108a6c03e1620fcb71772e5212b1aab745e32791d1b50bc2cb9ae6197e4f1d012
content-length: 103
content-type: application/json;charset=UTF-8
origin: https://www.chat.com
referer: https://www.chat.com/
sec-ch-ua: "Google Chrome";v="89", "Chromium";v="89", ";Not A Brand";v="99"
sec-ch-ua-mobile: ?0
sec-fetch-dest: empty
sec-fetch-mode: cors
sec-fetch-site: same-site
user-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 11_1_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.128 Safari/537.36
x-account-id: 121c7942-b51d-4fba-932a-74f3df74b215
x-member-id: 1234
x-team-id: 1234
{fileName: "16188033640933e8796c2644e41653c1d0a6286c79c7c", title: "screenshot.jpeg"}
fileName: "16188033640933e8796c2644e41653c1d0a6286c79c7c"
title: "screenshot.jpeg"
imformation for POST Request URL
Request URL: https://11.chat.com/message-api/v1/teams/1234/rooms/1234/posts
Request Method: POST
Status Code: 200
Remote Address: 11.111.11.11:111
Referrer Policy: strict-origin-when-cross-origin
access-control-allow-origin: *
access-control-expose-headers: Accept-Ranges,Content-Encoding,Content-Length,Content-Range
content-encoding: gzip
content-type: application/json; charset=utf-8
date: Mon, 11 Apr 2020 01:36:07 GMT
chat-correlationid: 600509c0-a0c0-11eb-8717-a38bfaeb5981
server: nginx/1.14.0 (Ubuntu)
vary: Accept-Encoding
x-powered-by: Express
:authority: 11.chat.com
:method: POST
:path: /message-api/v1/teams/1234/rooms/1234/posts
:scheme: https
accept: application/vnd.tosslab.chat-v2+json
accept-encoding: gzip, deflate, br
accept-language: ja,en-US;q=0.9,en;q=0.8,es;q=0.7
authorization: bearer c122a8c2c975a23f73141320f6ad0fab108a6c03e1620fcb71772e520b1aab745e32791d1b50bc2cb9a1237e4f1d07f6
content-length: 56
content-type: application/json;charset=UTF-8
origin: https://www.chat.com
referer: https://www.chat.com/
sec-ch-ua: "Google Chrome";v="89", "Chromium";v="89", ";Not A Brand";v="99"
sec-ch-ua-mobile: ?0
sec-fetch-dest: empty
sec-fetch-mode: cors
sec-fetch-site: same-site
user-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 11_1_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.128 Safari/537.36
x-account-id: 121c7942-b51d-4fba-932a-74f3df74b215
x-member-id: 1234
x-team-id: 1234
{title: "TEST", content: "test", fileIds: [1234]}
content: "test"
fileIds: [1234]
title: "TEST"
imformation for files Request Response
{"id":111,"fromEntity":1234,"teamId":1234,"info":{"inviteUsers":[],"createInfo":{"members":[],"pg_members":[],"ch_members":[]}},"pollId":null,"feedbackType":null,"feedbackId":-1,"status":"created","messageId":1483745833,"time":1618803367054,"toEntity":[17274139],"message":{"id":1483745833,"teamId":13481330,"writerId":13489639,"contentType":"post","permission":740,"updatedAt":"2021-04-19T03:36:07.049Z","createdAt":"2021-04-19T03:36:07.049Z","isThreaded":false,"isEdited":false,"sharedMessages":[],"attachments":[{"content":{"connectInfo":[],"extraInfo":{"thumbnailUrl":"https://chat-box.com/files-thumb/13481330/16188033640933e8796c2644e41653c1d0a6286c79c7c","smallThumbnailUrl":"https://chat-box.com/files-thumb/13481330/16188033640933e8796c2644e41653c1d0a6286c79c7c?size=80","mediumThumbnailUrl":"https://chat-box.com/files-thumb/13481330/16188033640933e8796c2644e41653c1d0a6286c79c7c?size=320","largeThumbnailUrl":"https://chat-box.com/files-thumb/13481330/16188033640933e8796c2644e41653c1d0a6286c79c7c?size=640","width":985,"height":589},"todo":{},"drive":{},"filterType":"image","externalShared":false,"externalUrl":null,"externalCode":null,"fileUrl":"https://files.chat.com/files-private/1234/16188033640933e8796c2644e41653c1d0a6286c79c7c","serverUrl":"s3","ext":"jpeg","size":235967,"icon":"image","type":"image/jpeg","filename":"16188033640933e8796c2644e41653c1d0a6286c79c7c","name":"screenshot.jpeg","title":"screenshot.jpeg"},"contentType":"file","id":1111}],"mentions":[],"info":{"mention":[]},"likedCount":0,"commentCount":0,"formatKey":null,"isFormatted":false,"todoId":null,"postId":null,"pollId":null,"feedbackId":-1,"shareEntities":[1234],"status":"created","linkPreviewId":null,"content":{"title":"TEST","body":"test","connectInfo":[]},"updateTime":1618803367049,"createTime":1618803367049,"deleterId":null,"from":"web"}}
code
import urllib.request, json
import requests
import mimetypes
from requests_toolbelt import MultipartEncoder
from datetime import datetime as dt
#Header information
LOGIN_API_ENDPOINT = "https://11.chat.com/inner-api/token"
BOARD_POST_API_ENDPOINT = "https://11.chat.com/message-api/11/teams/{0}/rooms/{1}/posts"
BOARD_POST_FILE_UPLOAD_API_ENDPOINT = "https://upload.chat.com/file-api/11/teams/{0}/rooms/{1}/attachment/files"
BOARD_POST_COMMENT_ENDPOINT = "https://11.chat.com/-api/11/teams/{0}/posts/{1}/comments"
BOARD_GET_SEARCH_ENDPOINT = "https://11.chat.com/api/teams/{0}/search"
ROOM_ID = "12345"
#login information
login = {"username":"123",
"password":"123",
"platform":"web",
"grant_type":"password"}
url = LOGIN_API_ENDPOINT
method = "POST"
headers = {"Content-Type" : "application/json;charset=UTF-8",
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.120 Safari/537.36",
"Origin": "https://www.chat.com",
"Accept": "application/vnd.tosslab.chat-v4+json"}
# DateTime
strDate = dt.now().strftime("%Y/%m/%d")
strTime = dt.now().strftime("%H:%M:%S")
#Python for Json change
login_data = login
token_obj = {}
json_data = json.dumps(login_data).encode("utf-8")
# login
# http for POST
request = urllib.request.Request(url, data=json_data, method=method, headers=headers)
with urllib.request.urlopen(request) as response:
token_obj = json.loads(response.read().decode("utf-8"))
print(token_obj)
print(token_obj["token_type"])
print(token_obj["access_token"])
# chat server file upload
url = BOARD_POST_FILE_UPLOAD_API_ENDPOINT.format(TEAM_ID,ROOM_ID)
# --------------------------------------------1-------------------
#MIMETYPE change file
fileName = 'C:\\Users\\test\\Desktop\\screenshot.jpeg'
XLSX_MIMETYPE = mimetypes.guess_type(fileName)[0]
print(XLSX_MIMETYPE)
fileDataBinary = open(fileName, 'rb')
files = {'file': ('screenshot.jpeg', fileDataBinary, XLSX_MIMETYPE)}
#Uploading Data
m = MultipartEncoder(
fields={'title': 'screenshot.jpeg',
'file': ('screenshot.jpeg', fileDataBinary, XLSX_MIMETYPE)}
)
auth = "{0} {1}".format(token_obj["token_type"], token_obj["access_token"])
headers = {'Content-Type' : m.content_type, 'Authorization' : auth}
response = requests.post(url,data=m,headers=headers)
print(response.status_code)
print(response.content)
return_file_data = json.loads(response.content)
auth = "{0} {1}".format(token_obj["token_type"], token_obj["access_token"])
#Post chat
url = BOARD_POST_API_ENDPOINT.format(TEAM_ID,ROOM_ID)
print(url)
# print(return_file_data["id"])
fileList = []
fileList.append(return_file_data["id"])
payload = {"title":"test",
"content":"hello python world",
"fileIds":fileList}
title: "TEST"
print(payload)
headers1 = {'Content-Type' : 'application/json;charset=UTF-8', 'Authorization' : auth}
print(headers1)
response = requests.post(url,data=json.dumps(payload).encode("utf-8"),headers=headers1)
error
{'access_token': '12396dae54be29417882f5c5d72822121aa5a0', 'expires_in': 43200, 'refresh_token': '123139ec591043f23046f3b4b512134b5db4f7a445212550b6de60', 'token_type': 'bearer', 'ts': 1618805067661}
bearer
12396dae54be29417882f5c5d72822121aa5a0
image/jpeg
503
b''
Traceback (most recent call last):
File "c:/Users/test/Documents/test/test_post.py", line 78, in <module>
return_file_data = json.loads(response.content)
File "C:\Users\test\AppData\Local\Programs\Python\Python38-32\lib\json\__init__.py", line 357, in loads
return _default_decoder.decode(s)
File "C:\Users\test\AppData\Local\Programs\Python\Python38-32\lib\json\decoder.py", line 337, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "C:\Users\test\AppData\Local\Programs\Python\Python38-32\lib\json\decoder.py", line 355, in raw_decode
raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
PS C:\Users\test>
If anyone knows, please let me know.
As per the error logs it seems you are getting empty data in response.
Status 503 means there might be error in API, so the response is empty.
You can directly use resp.json() method instead of json.dump(resp.content)
return_file_data = response.json()
Also add check for response.status_code == 200 and then take content from the response.

Differences in sending a multipart/form-data post via requests

I've got problem while trying to post the file to the server. I'm trying to make file upload script to server, this server is very 'Sensitive to correctness post request'
I debugged page that is sending the file to server and browser send this (TextView):
POST http://example.com/post HTTP/1.1
Host: example.com
Connection: keep-alive
Content-Length: 20625
Accept: application/json, text/javascript, */*; q=0.01
Origin: http://example.com
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.104 Safari/537.36
Content-Type: multipart/form-data; boundary=----WebKitFormBoundarykGHBkXoER9gNuVna
Referer: http://example.com/foo
Accept-Encoding: gzip, deflate
Accept-Language: pl-PL,pl;q=0.8,en-US;q=0.6,en;q=0.4,pt;q=0.2
------WebKitFormBoundarykGHBkXoER9gNuVna
Content-Disposition: form-data; name="files[]"; filename="file.zip"
Content-Type: application/octet-stream
...raw file data...
------WebKitFormBoundarykGHBkXoER9gNuVna--
However, my script is sending this (TextView):
POST http://example.com/post HTTP/1.1
Host: example.com
Connection: keep-alive
Accept-Encoding: gzip, deflate
Accept: */*
User-Agent: python-requests/2.18.1
Content-Length: 20604
--f8c266cf436941019c5a80c7d4779a57
Content-Disposition: form-data; name="files[]"; filename="file.zip"
Content-Type: application/zip
...raw file data...
--f8c266cf436941019c5a80c7d4779a57--
With causes error on server, additional note: this error started when I changed files=files to data=files
Current Code:
files = MultipartEncoder({'files[]': (filename, open(local_path,'rb'), mimetype)})
UploadFile = requests.post(self.UploadURL, data=files, allow_redirects=False)
Working code:
files = {'files[]': (filename, open(local_path,'rb'), mimetype)}
UploadFile = requests.post(self.UploadURL, files=files, allow_redirects=False)
I'm using MultipartEncoder to allow sending huge files.
I see that biggest mismatch is "boundary", but why this 'boundary' is generating in working code but in Current code not?
How to fix that?
You are not setting the Content-Type header, the MultipartEncoder provides it for you:
files = MultipartEncoder({'files[]': (filename, open(local_path,'rb'), mimetype)})
UploadFile = requests.post(
self.UploadURL, data=files, allow_redirects=False,
headers={'Content-Type': files.content_type})
The header must come from the multi-part encoding, because it is responsible for picking the boundary used to deliniate the various MIME parts in the multipart response. In your upload that's:
--f8c266cf436941019c5a80c7d4779a57
but it is generated at random each time your code runs. The header provided would look like:
Content-Type: multipart/form-data; boundary=--f8c266cf436941019c5a80c7d4779a57

Python requests' POST file fails when trying to upload a WordPress Theme to Host

I'm trying to write a python script that would help me install a theme remotely. Unfortunately, the upload part doesn't play nice, trying to do it with requests' POST helpers.
The HTTP headers of a successful upload look like this:
http://127.0.0.1/wordpress/wp-admin/update.php?action=upload-theme
POST /wordpress/wp-admin/update.php?action=upload-theme HTTP/1.1
Host: 127.0.0.1
User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:53.0) Gecko/20100101 Firefox/53.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Content-Type: multipart/form-data; boundary=---------------------------2455316848522
Content-Length: 2580849
Referer: http://127.0.0.1/wordpress/wp-admin/theme-install.php
Cookie: wordpress_5bd7a9c61cda6e66fc921a05bc80ee93=admin%7C1497659497%7C4a1VklpOs93uqpjylWqckQs80PccH1QMbZqn15lovQu%7Cee7366eea9b5bc9a9d492a664a04cb0916b97b0d211e892875cec86cf43e2f9d; wordpress_test_cookie=WP+Cookie+check; wordpress_logged_in_5bd7a9c61cda6e66fc921a05bc80ee93=admin%7C1497659497%7C4a1VklpOs93uqpjylWqckQs80PccH1QMbZqn15lovQu%7C9949f19ef5d900daf1b859c0bb4e2129cf86d6a970718a1b63e3b9e56dc5e710; wp-settings-1=libraryContent%3Dbrowse; wp-settings-time-1=1497486698
Connection: keep-alive
Upgrade-Insecure-Requests: 1
-----------------------------2455316848522: undefined
Content-Disposition: form-data; name="_wpnonce"
b1467671e0
-----------------------------2455316848522
Content-Disposition: form-data; name="_wp_http_referer"
/wordpress/wp-admin/theme-install.php
-----------------------------2455316848522
Content-Disposition: form-data; name="themezip"; filename="oedipus_theme.zip"
Content-Type: application/octet-stream
PK
HTTP/1.1 200 OK
Date: Thu, 15 Jun 2017 01:33:25 GMT
Server: Apache/2.4.25 (Win32) OpenSSL/1.0.2j PHP/7.1.1
X-Powered-By: PHP/7.1.1
Expires: Wed, 11 Jan 1984 05:00:00 GMT
Cache-Control: no-cache, must-revalidate, max-age=0
X-Frame-Options: SAMEORIGIN
Keep-Alive: timeout=5, max=100
Connection: Keep-Alive
Transfer-Encoding: chunked
Content-Type: text/html; charset=UTF-8
----------------------------------------------------------
To create a simple session for WP, in order to use later for uploads:
global wp_session
def wpCreateSession(uname, upassword, site_link):
"""
:param uname: Username for the login.
:param upaswword: Password for the login.
:param site_link: Site to login on.
:return: Returns a sessions for the said website.
"""
global wp_session
wp_session = requests.session()
wp_session.post(site_link, data={'log' : uname, 'pwd' : upassword})
To upload the said file to WP, using the wp_session global:
def wpUploadTheme(file_name):
global wp_session
try:
with open(file_name, 'rb') as up_file:
r = wp_session.post('http://127.0.0.1/wordpress/wp-admin/update.php', files = {file_name: up_file})
print "Got after try."
finally:
up_file.close()
And this last bit is where it doesn't work, the upload is not successful and I get returned to WordPress' basic 404.
I have also tried requests_toolbelt MultiPart_Encoder to no avail.
Question: 'requests' POST file fails when trying to upload
Check your files dict, your dict is invalid
files = {file_name: up_file}
Maybe you need a full blown files dict, for instance:
files = {'themezip': ('oedipus_theme.zip',
open('oedipus_theme.zip', 'rb'),
'application/octet-stream', {'Expires': '0'})}
From docs.python-requests.org
files = {'file': open('test.jpg', 'rb')}
requests.post(url, files=files)
From SO Answer Upload Image using POST form data in Python-requests

Log in to website using requests

I am currently trying to get data off http://www.spotrac.com/ that requires being signed in. My current attempt uses this code(which I got by going through a bunch of other stack overflow questions on a similar topic)
from bs4 import BeautifulSoup as bs
from requests import session
payload = {
'id': 'contactForm',
'cmd': 'http://www.spotrac.com/signin/submit/',
'email': '*****',
'password': '*****'
}
with session() as c:
r_login = c.post('http://www.spotrac.com/signin/', data=payload)
print(r_login.headers)
response = c.get('http://www.spotrac.com/nba/cleveland-cavaliers/lebron-james')
print(response.cookies)
soup=bs(response.text, 'html.parser')
with open('ex.html','w') as f:
f.write(soup.prettify())
My current code does everything right, except I am not logged in when I'm making the request.
Thanks
You're sending POST request to a wrong URL, and with an incorrect payload as well.
POST http://www.spotrac.com/signin/submit/ HTTP/1.1
Host: www.spotrac.com
Connection: keep-alive
Content-Length: 86
Cache-Control: max-age=0
Origin: http://www.spotrac.com
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36
Content-Type: application/x-www-form-urlencoded
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
Referer: http://www.spotrac.com/signin/
Accept-Encoding: gzip, deflate
Accept-Language: en-US,en;q=0.8
Cookie: cisession=a%3A5%3A%7Bs%3A10%3A%22session_id%22%3Bs%3A32%3A%2206021e191bdbbaf955f111f67b961056%22%3Bs%3A10%3A%22ip_address%22%3Bs%3A11%3A%22119.9.105.6%22%3Bs%3A10%3A%22user_agent%22%3Bs%3A108%3A%22Mozilla%2F5.0+%28Windows+NT+6.1%3B+WOW64%29+AppleWebKit%2F537.36+%28KHTML%2C+like+Gecko%29+Chrome%2F55.0.2883.87+Safari%2F537.36%22%3Bs%3A13%3A%22last_activity%22%3Bi%3A1485487245%3Bs%3A9%3A%22user_data%22%3Bs%3A0%3A%22%22%3B%7Dd6089620b21ecce6837161605055ae04; _ga=GA1.2.910256341.1481865346; _gali=contactForm
redirect=http%3A%2F%2Fwww.spotrac.com%2F&email=sdfs%40gmail.com&password=lkasjdflksjad
HTTP/1.1 302 Found
Server: nginx
Date: Fri, 27 Jan 2017 04:21:16 GMT
Content-Type: text/html
Content-Length: 0
Connection: keep-alive
Set-Cookie: cisession=a%3A5%3A%7Bs%3A10%3A%22session_id%22%3Bs%3A32%3A%22badb1275aee1cdad6736a6b4bb1ce809%22%3Bs%3A10%3A%22ip_address%22%3Bs%3A11%3A%22119.9.105.6%22%3Bs%3A10%3A%22user_agent%22%3Bs%3A108%3A%22Mozilla%2F5.0+%28Windows+NT+6.1%3B+WOW64%29+AppleWebKit%2F537.36+%28KHTML%2C+like+Gecko%29+Chrome%2F55.0.2883.87+Safari%2F537.36%22%3Bs%3A13%3A%22last_activity%22%3Bi%3A1485490876%3Bs%3A9%3A%22user_data%22%3Bs%3A0%3A%22%22%3B%7Dad486866c32cac526487707cea85b8a9; expires=Fri, 10-Feb-2017 04:21:16 GMT; path=/
Location: http://www.spotrac.com/register/
X-Powered-By: PleskLin
MS-Author-Via: DAV
As you can see from above session, the correct url should be http://www.spotrac.com/signin/submit/, and payload string is redirect=http%3A%2F%2Fwww.spotrac.com%2F&email=sdfs%40gmail.com&password=lkasjdflksjad, which is basically:
payload = {'redirect': 'http://www.spotrac.com/',
'email': mail_address,
'password': password}
Also make sure simulate headers with correct parameters, then you're good to go.

Categories

Resources