0

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

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

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)

But I get error.

<!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>
Rahul
  • 10,830
  • 4
  • 53
  • 88
  • 1
    When I run that `curl` command, I get the exact same output. So, try fixing your request. – Fejs Nov 18 '16 at 12:23
  • Possible duplicate of [Post JSON using Python Requests](http://stackoverflow.com/questions/9733638/post-json-using-python-requests) – Klaus D. Nov 18 '16 at 12:24
  • maybe they are problem in server. – furas Nov 18 '16 at 12:29
  • in your documentation is example - link to page which display result of query (before `Case 2`) It use `API` to get data so you can use `DevTools` in Chrome/Frirefox to see request. They even can create `curl` code. – furas Nov 18 '16 at 12:33

1 Answers1

4

Try converters which can convert curl into requests

http://curl.trillworks.com/

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


EDIT:

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

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

-

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"}'

-

And this gives some results too.

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)

I use

  • https:// instead of http://
  • /api/queries instead of /queries
  • json= instead of data=
furas
  • 134,197
  • 12
  • 106
  • 148