将curl查询转换为请求

2024-10-01 15:35:54 发布

您现在位置:Python中文网/ 问答频道 /正文

我想通过以下网址获取文件: https://pairbulkdata.uspto.gov/#/api-documentation

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

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

下面是我正在尝试的python代码:

^{pr2}$

但我搞错了。在

<!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>


Tags: thehttptitlerequesthtmltypenoterror
1条回答
网友
1楼 · 发布于 2024-10-01 15:35:54

尝试将curl转换为requests的转换器

http://curl.trillworks.com/

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


编辑:

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

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

它似乎使用了带有/api/queries的url,但是文档显示/queries

-

这段代码以JSON的形式给了我一些数据,所以它可能可以工作

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

-

这也给出了一些结果。在

^{pr2}$

我使用

  • https://而不是{}
  • /api/queries而不是{}
  • json=而不是{}

相关问题 更多 >

    热门问题