首页 > 解决方案 > CURL 有效,但不能翻译成 Python

问题描述

以下 CURL 代码可在 cmd 中完美运行:

curl -X POST -H "Authorization: Bearer MY_KEY" ^
-H "Content-Type: multipart/form-data;" ^
-F "center=40.430,-3.702" ^
-F "propertyType=homes" ^
-F "distance=15000" ^
-F "operation=sale" ^
"https://api.idealista.com/3.5/es/search"

,但如果我使用https://curl.trillworks.com/将其翻译成 Python 代码,如下所示:

import requests

headers = {
    'Authorization': 'Bearer MY_KEY',
    'Content-Type': 'multipart/form-data;',
}

files = {
    'center': (None, '40.430,-3.702'),
    'propertyType': (None, 'homes'),
    'distance': (None, '15000'),
    'operation': (None, 'sale'),
}

response = requests.post('https://api.idealista.com/3.5/es/search', headers=headers, files=files)

,好吧,然后它不再起作用,给出错误500。似乎是什么问题?

标签: pythoncurl

解决方案


推荐阅读