LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 06-03-2020, 10:48 PM   #1
snowman81
Member
 
Registered: Aug 2006
Location: Michigan
Distribution: Ubuntu
Posts: 279

Rep: Reputation: 30
Urllib error when calling pubchempy


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 Aspirin
Code:
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'
 
Old 06-04-2020, 02:41 AM   #2
shruggy
Member
 
Registered: Mar 2020
Posts: 994

Rep: Reputation: Disabled
Quote:
Originally Posted by snowman81 View Post
Code:
input = sys.argv[1]

pcp.download('PNG', 'test.png', '(input)', 'name')
This is obviously wrong. The last line probably should be
Code:
pcp.download('PNG', 'test.png', input, 'name')
 
1 members found this post helpful.
Old 06-04-2020, 06:40 AM   #3
snowman81
Member
 
Registered: Aug 2006
Location: Michigan
Distribution: Ubuntu
Posts: 279

Original Poster
Rep: Reputation: 30
Damn, Thanks! Can I do the same ting with test.png to make it like 'input'.png?

Last edited by snowman81; 06-04-2020 at 06:44 AM.
 
Old 06-04-2020, 07:56 AM   #4
SoftSprocket
Member
 
Registered: Nov 2014
Posts: 305

Rep: Reputation: Disabled
It's called string concatenation.

Code:
input + '.png'
(as long as input is a string)
 
  


Reply

Tags
pubchempy, python, urllib


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
urllib problem in python kahn Programming 4 01-14-2018 09:18 PM
[SOLVED] Python urllib finding the real URI of the start page ocpaul20 Programming 3 05-03-2015 09:54 PM
vfork - suspends the calling process or the calling thread? zmau Linux - Software 3 04-21-2015 02:38 PM
odd recursion: calling "by hand" vs calling by cronscript... prx Programming 4 02-12-2005 04:59 PM
Strange error calling fopen() twice Nerox Programming 4 07-05-2004 07:27 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:17 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration