Note that there are some explanatory texts on larger screens.

plurals
  1. POError while importing Flickr api using Python on Google App Engine
    text
    copied!<p>I'm trying to do a really simple Python webservice. It makes a 'photo.search' using the Flickr API and returns the titles and photos' url.</p> <p>This webservice will be hosted on Google App Engine.</p> <p>This is what I actually have right now : </p> <pre><code>import webapp2 from urllib import urlencode, urlopen from xml.dom import minidom from google.appengine.api import urlfetch class MainPage(webapp2.RequestHandler): def get(self): self.response.headers['Content-Type'] = 'text/plain' data = _doget('flickr.photos.search', text='to_search', per_page='2') self.response.write('Ok') def _prepare_params(params): for (key, value) in params.items(): if isinstance(value, list): params[key] = ','.join([item for item in value]) return params def _doget(method, auth=False, **params): params = _prepare_params(params) url = 'http://flickr.com/services/rest/?api_key=%s&amp;method=%s&amp;%s%s'% \ ('stackoverflow_key', method, urlencode(params), _get_auth_url_suffix(method, auth, params)) result = urlfetch.fetch(url) minidom.parse(result.content) return result application = webapp2.WSGIApplication([ ('/', MainPage), ], debug=True) </code></pre> <p>I'm a beginner at Python, so I apologize if I did huge mistakes :) I tried several tutorials and sample codes that didn't work. </p> <p>The imports are making a 500 server error</p> <pre><code>Error: Server Error The server encountered an error and could not complete your request. If the problem persists, please report your problem and mention this error message and the query that caused it. </code></pre> <p>Does anyone can tell me what's wrong with it ? </p> <p>If anyone have samples code that did the trick, could be nice.</p> <p>Thanks a lot in advance for your time!! :D</p> <p><em><strong>EDIT :</em></strong> </p> <p>All right, I changed my code, it's way simplier than before, for testing : </p> <pre><code>import webapp2 from urllib import urlencode, urlopen from xml.dom import minidom from google.appengine.ext.webapp.util import run_wsgi_app import hashlib import os HOST = 'http://api.flickr.com' API = '/services/rest' API_KEY = 'my_key' class MainPage(webapp2.RequestHandler): def get(self): self.response.headers['Content-Type'] = 'text/html' data = _doget('flickr.photos.search', auth=False, text='to_search', per_page='1') if data: self.response.write(data) else: self.response.write('Error') def _doget(method, **params): url = '%s%s/?api_key=%s&amp;method=%s&amp;%s&amp;format=json'% \ (HOST, API, API_KEY, method, urlencode(params)) res = urlfetch.fetch(url).content # Flickr JSON api returns not valid JSON, which wrapped with "jsonFlickrApi(...)", so we get rid of it. if 'jsonFlickrApi(' in res: return res[14:-1] return json.loads(res) application = webapp2.WSGIApplication([ ('/', MainPage), ], debug=True) </code></pre> <p>When I copy/paste this url, it works perfectly. My aim is to return the data as flickr returns it. But still not working. The print isn't even shown :(</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload