将curl查询转换为请求 [英] translate curl query to requests

查看:92
本文介绍了将curl查询转换为请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正尝试在以下位置使用文档:
https:// pairbulkdata.uspto.gov/#/api-documentation

I was trying to get hand on using documentation at: https://pairbulkdata.uspto.gov/#/api-documentation

但是,当我尝试这些查询时,出现错误消息。
我正在尝试将curl查询转换为python请求。

However when I tried those query, I got error message. I am trying to translate curl query to python requests.

curl -i -X POST -H "Content-Type:application/json" -d '{"searchText":"medicine AND diabetes","qf": "patentTitle"}' http://pairbulkdata.uspto.gov/queries

这是我正在尝试的python代码:

Here is the python code that I am trying:

import requests

data = {"searchText":"medicine AND diabetes","qf": "patentTitle"}

url = "http://pairbulkdata.uspto.gov/queries"

header = {"Content-Type":"application/json"}

r = requests.post(url, data = data, headers=header)

但是我遇到了错误。

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">\n<HTML><HEAD><META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">\n<TITLE>ERROR: The request could not be satisfied</TITLE>\n</HEAD><BODY>\n<H1>ERROR</H1>\n<H2>The request could not be satisfied.</H2>\n<HR noshade size="1px">\nBad request.\n<BR clear="all">\n<HR noshade size="1px">\n<PRE>\nGenerated by cloudfront (CloudFront)\nRequest ID: OIhwX7a3zVJq04M_qf0sjWhuke3fHb1-6wFJsN7UX_Rp2w_gzebTGA==\n</PRE>\n<ADDRESS>\n</ADDRESS>\n</BODY></HTML>

推荐答案

尝试使用可以将 curl 转换为请求 的转换器p>

http://curl.trillworks.com/

http://curl.trillworks.com/

https://shibukawa.github .io / curl_as_dsl / index.html

编辑:

我检查了文档,并且有指向使用API​​获取数据的页面的链接

I checked documentation and there is link to page which uses API to get data

https://pairbulkdata.uspto.gov/#/search?q=medicine %20AND%20diabetes& sort = applId%20asc

似乎它在 / api / queries ,但文档显示 /查询

It seems it uses url with /api/queries but documentations shows /queries

-

此代码为我提供了一些JSON数据-所以可能可行

This code gives me some data as JSON - so probably it works

curl 'https://pairbulkdata.uspto.gov/api/queries' -X POST -H 'Content-Type: application/json' -d '{"searchText":"medicine AND diabetes","qf": "patentTitle"}'

-

这也给出了一些结果。

import requests

url = "https://pairbulkdata.uspto.gov/api/queries"

headers = {"Content-Type":"application/json"}

data = {"searchText":"medicine AND diabetes","qf": "patentTitle"}

r = requests.post(url, json=data, headers=headers)

print(r.text)

我使用


  • https:// 而不是 http://

  • / api / queries 而不是 / queries

  • json = 而不是 data =

  • https:// instead of http://
  • /api/queries instead of /queries
  • json= instead of data=

这篇关于将curl查询转换为请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆