简体   繁体   English

如何发送发帖请求并获取文件? Python Django

[英]How send post request and get file? Python Django

One site пenerating iPXE build imagea file that I need to download by sending a request. 我需要通过发送请求来下载iPXE构建imagea文件的一个站点。

I want to make a request for a post on the 3th site (rom-o-matic.eu), and get a file from site. 我想在第三个网站(rom-o-matic.eu)上发帖,并从该网站获取文件。 Is this possible? 这可能吗?

My example is this: 我的例子是这样的:

def requestPOST(request):
    values = {'wizardtype': 'standard', 
    'outputformatstd': 'bin/ipxe.usb', 
    'embed': '#!ipxe dhcp route}', 
    'gitrevision': 'master'}

    r = requests.post("https://rom-o-matic.eu/", verify=False, data={values})
    return()

What should this return? 这应该返回什么?

Thanks. 谢谢。

import requests
import shutil

def downloadPOST(outpath):
    values = {
        'wizardtype': 'standard', 
        'outputformatstd': 'bin/ipxe.usb', 
        'embed': '#!ipxe dhcp route}', 
        'gitrevision': 'master',
    }

    r = requests.get("https://rom-o-matic.eu/", data={values}, verify=False, stream=True)

    if r.status_code != 200:
        raise ValueError('Status code != 200')

    with open(outpath, 'wb') as f:
        r.raw.decode_content = True
        shutil.copyfileobj(r.raw, f)  

Based on How to download image using requests 基于如何使用请求下载图像

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM