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
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值