I have a parser written in Python (aiohttp, bs4). One of the functions of the parser is to access a file by a link (example: https://modsfire.com/d/Mwv01aESgj73zx7).
import aiohttp
import yarl
import asyncio
from pprint import pprint
MODSFIRE_URL = "https://modsfire.com/"
COOKIES = {
'_ga_JXQKZFEW04': 'GS1.1.1718453797.5.1.1718456834.0.0.0',
'_ga': 'GA1.1.733263822.1718378970',
'old_date': 'eyJpdiI6IlA0NXg3aDV6QVBzazFMVHRibjR3NWc9PSIsInZhbHVlIjoiXC80RWt3ZHNNdEFQMks0SGhjdEltNEE9PSIsIm1hYyI6ImM3Mzg4NzkyZTA5YjI5YjRiZDc2YjdkODIyMDEwNDE4MzBmZWJlYWU0MTc0ZmMxZGQxNTc0MjQyN2NlMGE1YzYifQ%3D%3D',
'fid': 'eyJpdiI6IjFKSjJ1VDVaSHVpdmh4ZWdJcjBiZ2c9PSIsInZhbHVlIjoicTArdExGeDdPRFpua0dVWm1vZ1pRZz09IiwibWFjIjoiNjJjZDZjZDg1NzgxODk1NmJkNmNmMDBiOTg1OWUzMTM0MmU1MjI3ODExZjkzMGRkOTBhMWVmM2RkOTJhMGM3YSJ9',
'XSRF-TOKEN': 'eyJpdiI6ImNNM20wcjhLMnBBMW9sRG5VZm9rK1E9PSIsInZhbHVlIjoiRU9MRUVcLzExN0RiU1d2VXlXY0ExQ0tpbVwveGlDbDdiTFNpbURWSlZEZE4reEM0VlRxc1JWVFYyR3NLOTVwaGIyIiwibWFjIjoiMmUwOTNlYTIyYTkxMDZkNDJiNzY0NDE5ODY4ZDU1NGEwODMwNmIyYjZjZjliYzUxNTc3ZDZjNzA0ZGI5MTQwYiJ9',
'modsfire_session': 'eyJpdiI6Ikxia0dmMVwvMGtSQ3VyWWJBWHRadUZ3PT0iLCJ2YWx1ZSI6IjNmeFBkcmtWZ0I4S3l1WDB6eGhTT2JyTnBlajlcL3pxMGlubWNRR1NvUlZHQlI5eWMxVmpPelNhTzBjYUoyVXBzIiwibWFjIjoiODg5YTE2N2UzZGI1NDRhN2QwNGFlNjk3NDEwMDNkZTY5MThkZjJiZjE5ZDIyZGNlYjNhZWM1NDY2ODg4ZWU4NyJ9',
'referer_domain': 'eyJpdiI6ImdVM2lZYWRQdm1iNEkycXRJNGpRM3c9PSIsInZhbHVlIjoid1NmU0F5b2NiS0JpWk4yR051YVN2QT09IiwibWFjIjoiODExMDllOGQ4ZmU1Y2RjMWVkZTIxNmFhNzhiYzNmMTFkZWNmODVmZDc5NDFlMWJhNDhlMmNmNjE2MWQzZTIwYyJ9',
'cf_clearance': 'UFEt8KWYJuVxadyvHEgHGOcRxIzVrFYvF2h.KHdSeD8-1718456567-1.0.1.1-CmNj9kZt85DTea1QAvCxuIwwb3KzNJ96jRBsoM7r1oOOeMcNeLa3XS4osEElROQq0oely9xLAIj_U05z2sCiZg',
'a644b2a3a3018e5f62e31f82c6db5ae0': 'eyJpdiI6Ijl6eFwvWXp3UkpUWUhYcWVqYzlDb3R3PT0iLCJ2YWx1ZSI6IlI2YW1FZ2JkQmIyZm9wY0FUNkVEdGc9PSIsIm1hYyI6ImY5OGJlN2FkZjljZWYzNTM1ZjM5OGZjMmU1OGY0MWE2NTFiYjYyNTcwNDUzYzg1ZTJlNGNkMjc0ZmZiZjJiMTMifQ%3D%3D',
}
HEADERS = {
'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64; rv:127.0) Gecko/20100101 Firefox/127.0',
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8',
'Accept-Language': 'ru-RU,ru;q=0.8,en-US;q=0.5,en;q=0.3',
# 'Accept-Encoding': 'gzip, deflate, br, zstd',
'Referer': MODSFIRE_URL,
'Connection': 'keep-alive',
# 'Cookie': '_ga_JXQKZFEW04=GS1.1.1718453797.5.1.1718458248.0.0.0; _ga=GA1.1.733263822.1718378970; cf_clearance=UFEt8KWYJuVxadyvHEgHGOcRxIzVrFYvF2h.KHdSeD8-1718456567-1.0.1.1-CmNj9kZt85DTea1QAvCxuIwwb3KzNJ96jRBsoM7r1oOOeMcNeLa3XS4osEElROQq0oely9xLAIj_U05z2sCiZg',
'Upgrade-Insecure-Requests': '1',
'Sec-Fetch-Dest': 'document',
'Sec-Fetch-Mode': 'navigate',
'Sec-Fetch-Site': 'same-site',
'Sec-Fetch-User': '?1',
'Priority': 'u=1',
# Requests doesn't support trailers
# 'TE': 'trailers',
}
async def get_response_file(url):
session = aiohttp.ClientSession(headers=HEADERS, cookies=COOKIES)
response = await session.get(url, allow_redirects=True)
pprint(dict(response.request_info.headers))
print("===============")
pprint(dict(response.headers))
if response.status != 200:
return "Error"
filename = yarl.URL(response.url).name
response_headers = dict(response.headers)
if filename != "d.php":
response_headers["Content-Disposition"] = "attachment; filename=" + filename
response_headers["Content-Type"] = "application/octet-stream"
return response, response_headers
asyncio.run(get_response_file("https://modsfire.com/d/Mwv01aESgj73zx7"))
On my machine everything works – I get a 200 response. But as soon as I run this script in docker, wine or on my server – I get response 403.
On my machine the output is:
enter image description here
On the server, in the docker and in the wine:
enter image description here
My machine:
OS: Arch Linux x86_64
WM: bspwm
Kernel: 6.9.10-zen1-1-zen
Python 3.12.4
aiohttp==3.9.5
curl 8.8.0 (x86_64-pc-linux-gnu) libcurl/8.8.0 OpenSSL/3.3.1 zlib/1.3.1 brotli/1.1.0 zstd/1.5.6 libidn2/2.3.7 libpsl/0.21.5 libssh2/1.11.0 nghttp2/1.62.1 nghttp3/1.4.0
Release-Date: 2024-05-22
Docker version 27.0.3, build 7d4bcd863a
wine-9.13
Characteristics of my server:
enter image description here
- I was able to run the script in wine, using my computer as a proxy (using mitmproxy).
- I’ve also tried using public proxies – didn’t help
- The curl request to url works on my machine, and on my server, but in docker it doesn’t:
curl '<url>' -H 'User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:127.0) Gecko/20100101 Firefox/127.0' -H 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8' -H 'Accept-Language: ru-RU,ru;q=0.8,en-US;q=0.5,en;q=0.3' -H 'Accept-Encoding: gzip, deflate, br, zstd' -H 'Referer: https://modsfire.com/' -L -v
Why does the curl request work but the python script on aiohttp does not?
Петр Василий is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.