python - 无法将图像上传到 Ghost CMS
问题描述
有人知道使用 python 将图像上传到 Ghost CMS 吗?
url = "https://analisa.ifxid.trade/ghost/api/v3/admin/images/upload/"
headers = {'Authorization': 'Ghost {}'.format(token.decode()),'Content-Type': 'form-data;'}
files = {'file':('ifxb.png', open('ifxb.png', 'rb'))}
r = requests.post(url, headers=headers, files=files)
print(r.text)
结果
{"errors":[{"message":"Please select an image.","context":null,"type":"ValidationError","details":null,"property":null,"help":null,"code":null,"id":"e114da60-d7c9-11ea-972e-97f9c75664c6"}]}
解决方案
邮递员给了我答案,文件字典中缺少图片的内容类型。它现在应该可以工作了。
url = "https://analisa.ifxid.trade/ghost/api/v3/admin/images/upload/"
headers = {'Authorization': 'Ghost {}'.format(token.decode()),'Content-Type': 'form-data;'}
files = {'file':('ifxb.png', open('ifxb.png', 'rb'), 'image/png')}
r = requests.post(url, headers=headers, files=files)
print(r.text)
推荐阅读
- python - Django 表单既不显示也不集成在 HTML 中
- automation - 在自动化混合 android 移动应用程序时,一些定位器无法找到
- javascript - How to get slug from an URL JavaScript
- java - 应用程序中的 DB2 到 MSSQL 迁移错误“org.hibernate.MappingException:无法实例化 id 生成器”和“方言不支持序列”
- python - “试图以访问权限禁止的方式访问套接字”,同时尝试访问 spotify api
- haskell - 折叠二叉树时无法匹配预期类型
- ruby-on-rails - RoR 命令“rake routes”中止
- google-colaboratory - Google Colab 中的云 TPU 虚拟机?
- java - 如何在 Android 中以编程方式设置导航抽屉的背景颜色
- swift - 如何使用swift以编程方式根据数据设置滚动视图的高度