python给url传参数_我如何将图像作为python请求中的参数以及url作为第二个参数传递?...

Hi i want to pass image from view to api using request,with url.

here is my code:

def processImage(request):

image=request.FILES['image']

params = {'image': image }

url='http://127.0.0.1:8000/idealweight/'

outPut_Data=requests.post(url,params=params)

//i also tried this

img=image

and then passed:

outPut_Data=requests.post(url,img)

but did not worked.and this gives error in imgFinalPro few arguments passed.

I am calling this imgFinalPro function And here I want to receive the image:

def imgFinalPro(request,img):

print(request)

# image=request.FILES['image']

# image=img

image=request.FILES['image']

How I can receive the image here? CAn use for further processing?

解决方案

Send your files inside files field not inside params.

def processImage(request):

image=request.FILES['image']

files = {'image': image }

url='http://127.0.0.1:8000/idealweight/'

outPut_Data=requests.post(url, files=files)

I Assume imgFinalPro is your controller for post request. You can't get the image as params of your controller. The image is attached with your request

def imgFinalPro(request):

print(request)

# image=request.FILES['image']

# image=img

image=request.FILES['image']

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
`gradio.processing_utils.encode_url_or_file_to_base64` 是 Gradio 库的一个函,用于将给定的 URL 或文件路径转换为 Base64 编码的字符串。它的具体用法如下: ```python import gradio.processing_utils as processing_utils encoded_string = processing_utils.encode_url_or_file_to_base64(url_or_file_path) ``` - 首先,我们需要导入 `gradio.processing_utils` 模块,可以使用 `import gradio.processing_utils as processing_utils` 进行导入。 - 然后,我们可以调用 `processing_utils.encode_url_or_file_to_base64` 函,并将要转换的 URL 或文件路径作为参数传递给它。函将返回一个 Base64 编码的字符串。 请注意,`url_or_file_path` 参数既可以是一个 URL 字符串,也可以是一个文件路径字符串。 以下是一个示例,演示了如何使用 `gradio.processing_utils.encode_url_or_file_to_base64` 函来将 URL 或文件路径转换为 Base64 编码的字符串: ```python import gradio.processing_utils as processing_utils url = "https://example.com/image.jpg" file_path = "path/to/file.jpg" encoded_url = processing_utils.encode_url_or_file_to_base64(url) encoded_file = processing_utils.encode_url_or_file_to_base64(file_path) print(encoded_url) print(encoded_file) ``` 在上面的示例,我们首先导入了 `gradio.processing_utils` 模块。然后,我们分别将一个 URL 字符串和一个文件路径字符串传递给 `encode_url_or_file_to_base64` 函,并将结果存储在 `encoded_url` 和 `encoded_file` 变量。最后,我们打印出转换后的 Base64 编码的字符串。 希望这个示例能帮助你理解如何使用 `gradio.processing_utils.encode_url_or_file_to_base64` 函。如果你还有其他问题,请随时提问。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值