Article 549QA Urllib error when calling pubchempy

Urllib error when calling pubchempy

by
snowman81
from LinuxQuestions.org on (#549QA)
I have a really simple script that downloads a PNG file of a chemical. I call the script with an argument but I can't seem to pass the argument to the proper place. If I put "Aspirin" where it says "input" it works. I call the script like Code:python3 script.py AspirinCode:import pubchempy as pcp
import sys

input = sys.argv[1]

pcp.download('PNG', 'test.png', '(input)', 'name')

print (input)The error I get:

Code:Traceback (most recent call last):
File "/home/jyoung/.local/lib/python3.7/site-packages/pubchempy.py", line 271, in request
response = urlopen(apiurl, postdata)
File "/usr/lib/python3.7/urllib/request.py", line 222, in urlopen
return opener.open(url, data, timeout)
File "/usr/lib/python3.7/urllib/request.py", line 531, in open
response = meth(req, response)
File "/usr/lib/python3.7/urllib/request.py", line 641, in http_response
'http', request, response, code, msg, hdrs)
File "/usr/lib/python3.7/urllib/request.py", line 569, in error
return self._call_chain(*args)
File "/usr/lib/python3.7/urllib/request.py", line 503, in _call_chain
result = func(*args)
File "/usr/lib/python3.7/urllib/request.py", line 649, in http_error_default
raise HTTPError(req.full_url, code, msg, hdrs, fp)
urllib.error.HTTPError: HTTP Error 404: PUGREST.NotFound

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "josh.py", line 6, in <module>
pcp.download('PNG', 'test.png', '(input)', 'name')
File "/home/jyoung/.local/lib/python3.7/site-packages/pubchempy.py", line 462, in download
response = get(identifier, namespace, domain, operation, outformat, searchtype, **kwargs)
File "/home/jyoung/.local/lib/python3.7/site-packages/pubchempy.py", line 292, in get
response = request(identifier, namespace, domain, operation, output, searchtype, **kwargs).read()
File "/home/jyoung/.local/lib/python3.7/site-packages/pubchempy.py", line 274, in request
raise PubChemHTTPError(e)
File "/home/jyoung/.local/lib/python3.7/site-packages/pubchempy.py", line 1299, in __init__
raise NotFoundError(self.msg)
pubchempy.NotFoundError: 'PUGREST.NotFound'latest?d=yIl2AUoC8zA latest?i=5oZ4fgPbvQQ:-hJrI9mPWBM:F7zBnMy latest?i=5oZ4fgPbvQQ:-hJrI9mPWBM:V_sGLiP latest?d=qj6IDK7rITs latest?i=5oZ4fgPbvQQ:-hJrI9mPWBM:gIN9vFw5oZ4fgPbvQQ
External Content
Source RSS or Atom Feed
Feed Location https://feeds.feedburner.com/linuxquestions/latest
Feed Title LinuxQuestions.org
Feed Link https://www.linuxquestions.org/questions/
Reply 0 comments