コード例 #1
0
 def http_Resp(self):
     rslt = {}
     for sito in self.lst_urls:
         try:
             s = httplib2.Http()
             code, resp = s.request(sito, body=None)
             if code.previous:
                 xbmc.log(
                     "r1 http_Resp: %s %s %s %s" %
                     (code.status, code.reason, code.previous['status'],
                      code.previous['-x-permanent-redirect-url']),
                     level=xbmc.LOGNOTICE)
                 rslt['code'] = code.previous['status']
                 rslt['redirect'] = code.previous[
                     '-x-permanent-redirect-url']
                 rslt['status'] = code.status
             else:
                 rslt['code'] = code.status
         except httplib2.ServerNotFoundError as msg:
             # sia per mancanza di ADSL che per i siti non esistenti
             rslt['code'] = -2
         except socket.error as msg:
             # per siti irraggiungibili senza DNS corretti
             #[Errno 111] Connection refused
             rslt['code'] = 111
     return rslt
コード例 #2
0
ファイル: __init__.py プロジェクト: jaytoday/passtiche
def _process_request_with_httplib2(url, data=None):
    """Make the request and handle exception processing"""
    h = httplib2.Http()
    try:
        if data:
            datagen, headers = poster.encode.multipart_encode(data)
            data = ''.join(datagen)
            method = 'POST'
        else:
            headers = {}
            method = 'GET'
        response, body = h.request(url, method, headers=headers, body=data)
        data = _json_to_data(body)
        # Default case, Got proper response
        if response.status == 200:
            return data
        return _check_response(data)
    except httplib2.HttpLib2Error, e:
        log.error(e)
        raise FoursquareException(u'Error connecting with foursquare API')
コード例 #3
0
from google.appengine.api import users, memcache

from webapp2_extras import jinja2

import model.user as usr_mgt
import model.book as book_mgt
from lib import httplib2

from lib.googleapiclient.discovery import build

from lib.oauth2client.contrib import appengine

from model.appinfo import AppInfo

http = httplib2.Http(memcache)

decorator = appengine.oauth2decorator_from_clientsecrets(
    'client_secret.json',
    scope='https://www.googleapis.com/auth/books',
    message="MISSING_CLIENT_SECRETS_MESSAGE")
service = build("books", "v1", http=http)


class AddBook(webapp2.RequestHandler):
    @decorator.oauth_required
    def get(self):

        user = users.get_current_user()
        usr_info = usr_mgt.retrieve(user)