使用python请求格式化JSON for post命令...?URL中的jsonRequest参数

时间:2017-08-30 19:18:48

标签: python json post python-requests

我正在尝试向USGS EarthExplorer广告资源API提交POST请求。这从简单的登录开始。他们有一个测试页面:

https://earthexplorer.usgs.gov/inventory/documentation/test

允许您查看一些格式示例。对于登录示例,我能够提取按下按钮时提交的URL(用户和pw已更改):

https://earthexplorer.usgs.gov/inventory/json/v/1.4.0/login?jsonRequest=%7B%22username%22%3A%22user%22%2C%22password%22%3A%22pw%22%2C%22catalogId%22%3A%22EE%22%7D

但是,我似乎无法弄清楚如何使用请求库在Python中格式化它。我对其他人开放,但我现在正在使用请求。我试过创建一个字典:

creds = {"username": "user",
  "password": "pw",
  "authType": "",
  "catalogId": "EE"}

payload = json.dumps(creds)

当我致电requests.post(url, json=payload)时,我被告知我的用户名参数不存在。我也尝试了其他关键字,如数据和参数。

我注意到成功的URL中有jsonRequest参数,所以我尝试在那里创建一个字典:

creds2={"jsonRequest": [{"username": "user",
                    "password": "pw",
                    "authType": "",
                    "catalogId": "EE"}]} 

但这也不起作用。

有什么建议吗?谢谢!

1 个答案:

答案 0 :(得分:1)

You'll have to send a GET request and pass the creds in the query string using the params argument.

<style name="SplashTheme" parent="Theme.AppCompat.NoActionBar">
    <item name="android:windowBackground">@drawable/launch_screen</item>
</style>