我正在尝试通过请求从 steamworkshopdownloader.io 下载文件,但它始终返回 500 错误。我究竟做错了什么?我对请求不是很熟悉。
代码:
import requests
def downloadMap(map_id):
session = requests.session()
file = session.post("https://backend-02-prd.steamworkshopdownloader.io/api/details/file",
data={"publishedfileid": map_id})
print(file)
downloadMap("814218628")
答案 0 :(得分:1)
如果你想从这个 API 下载文件,试试这个代码,它改编自我之前发布的评论中的链接 (https://greasyfork.org/en/scripts/396698-steam-workshop-downloader/code) 并转换成 Python:
import requests
import json
import time
def download_map(map_id):
s = requests.session()
data = {
"publishedFileId": map_id,
"collectionId": None,
"extract": True,
"hidden": False,
"direct": False,
"autodownload": False
}
r = s.post('https://backend-01-prd.steamworkshopdownloader.io/api/download/request', data=json.dumps(data))
print(r.json())
uuid = r.json()['uuid']
data = f'{{"uuids":["{uuid}"]}}'
while True:
r = s.post('https://backend-01-prd.steamworkshopdownloader.io/api/download/status', data=data)
print(r.json())
if r.json()[uuid]['status'] == 'prepared':
break
time.sleep(1)
params = (('uuid', uuid),)
r = s.get('https://backend-01-prd.steamworkshopdownloader.io/api/download/transmit', params=params, stream=True)
print(r.status_code)
with open(f'./{map_id}.zip', 'wb') as f:
for chunk in r.iter_content(chunk_size=1024):
if chunk:
f.write(chunk)
download_map(814218628)
代码演示了如何使用 API 并将名为 814218628.zip(或提供的任何 map_id
)的文件下载到运行脚本的目录中,zip 存档包含 .udk 文件(游戏地图设计由虚幻引擎开发工具包创建)。