簡體   English   中英

為什么服務器對發布請求返回 500 響應

[英]Why does server returns 500 response to post request

我正在嘗試從帶有請求的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")

如果您想從此 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)

The code demonstrates how to use the API and downloads a file named 814218628.zip (or whatever map_id was provided) into the directory the script is run from, the zip archive contains the.udk file (Game map design created by the Unreal Engine Development成套工具)。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM