import urllibimport urllib2from Google.appengine.ext import webappfrom Google.appengine.ext.webapp import utilfrom Google.appengine.API import urlfetchreq_url = "https://sb-ssl.Google.com/safebrowsing/API/lookup"class MainHandler(webapp.RequestHandler): def get(self): self.response.out.write("""<HTML> <body> <form action='' method='POST'> <input type='text' name='url'> <input type='submit' value='submit!!'> </form> </body> </HTML>""") def post(self): post_data = {'clIEnt':'API','APIkey':'My-API-Key','appver':'1.5.2','pver':'3.0','url':"%s"% self.request.get('url') } data = urllib.urlencode(post_data) try: req = urlfetch.fetch(url = req_url,payload = data,method = urlfetch.POST,headers = {'Content-Type': 'application/x-www-form-urlencoded'}) if req.status_code == '200': self.response.out.write("success") self.response.out.write(req.content) else: self.response.out.write("Error code %s!!!"% req.status_code) except urllib2.URLError,e: self.response.out.write("Exception Raised") handleError(e)def main(): application = webapp.WsgiApplication([ ('/',MainHandler) ],deBUG=True) util.run_wsgi_app(application)if __name__ == '__main__': main()解决方法 您似乎没有遵循GET或POST方法的协议,而是通过POST传递应该是GET参数的内容.
试试这个方法:
import urllibfrom Google.appengine.API import urlfetchdef safe_browsing(url): """Returns True if url is safe or False is it is SUSPECT""" params = urllib.urlencode({ 'clIEnt':'API','APIkey':'yourkey','url': url }) url = "https://sb-ssl.Google.com/safebrowsing/API/lookup?%s" % params res = urlfetch.fetch(url,method=urlfetch.GET) if res.status_code >= 400: raise Exception("Status: %s" % res.status_code) return res.status_code == 204
哪个会像:
>>> safe_browsing('http://www.yahoo.com/')True@H_403_2@ 总结
以上是内存溢出为你收集整理的python – Google Safe-Browsing Lookup API中的无效请求全部内容,希望文章能够帮你解决python – Google Safe-Browsing Lookup API中的无效请求所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)