Jump to content
Sign in to follow this  

Python: 'urlopen' seems to crash the script?

Recommended Posts


(among other starter problems) I have the following problem:

The below script runs fine in the Mac OSX terminal.

But as an "run script" action (type "python") it hangs. When I delete the urlopen line the script runs to the end (but of course without a JSON result).

The small workflow is here: http://d.pr/f/K3t


So something seems to be wrong with the line "response = urllib2....":

import urllib2
import urllib
import json


params = {'url':url, 'title':'1','format':'json'}

response = urllib2.urlopen(endpoint+'?'+ urllib.urlencode(params))

    json_data = json.loads(response.read())
    print 'URL: '+json_data[u'long-url']
    #print 'Page title: '+json_data[u'title']
	print 'Sorry - could not find the long URL' 

How can I debug this?

How should I retrieve a JSON result from a webservice?


Thanks in advance!



Share this post

Link to post

Sorry, guys - I am not sure why, but the workfow works no.


I have to find out how to catch an illegal URL - with a legal URL everythings works as expected




Share this post

Link to post

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  
  • Create New...