5

मैं कैलेंडर के लिए Google एपीआई का उपयोग करने के लिए अपने पहले ऐप पर काम कर रहा हूं। मैंने Google उदाहरणों को यहां पढ़ा है: https://developers.google.com/google-apps/calendar/instantiateGoogle एपी एथ एचटीपी मॉड्यूल त्रुटि

पहली बार जब मैंने नीचे कार्यक्रम चलाया तो यह सफल रहा। मैंने अपने ऐप को अपने Google खाते तक पहुंचने की अनुमति दी और एप्लिकेशन ने मेरी ऐप-डायरेक्टरी में ऑथ जानकारी के साथ calendar.dat फ़ाइल बनाई। दायर नाम बदलने के बाद कोड ने काम बंद कर दिया था। मैंने पूरी तरह से फ़ाइल को हटा दिया है और इसे स्क्रैच से फिर से बनाया है, लेकिन त्रुटि बनी हुई है।

मुझे अभी भी Google प्रमाणीकरण पृष्ठ मिलता है और अभी भी पहुंच की पुष्टि कर सकता है, जिसके बाद मुझे एक संदेश मिलता है कि प्रमाणीकरण प्रवाह पूरा हो गया था।

इस कोड (मानक गूगल उदाहरण जो मैं अपने ऐप के विवरण के साथ में भरने) है:

import gflags 
import httplib2 

from apiclient.discovery import build 
from oauth2client.file import Storage 
from oauth2client.client import OAuth2WebServerFlow 
from oauth2client.tools import run 

FLAGS = gflags.FLAGS 

# Set up a Flow object to be used if we need to authenticate. This 
# sample uses OAuth 2.0, and we set up the OAuth2WebServerFlow with 
# the information it needs to authenticate. Note that it is called 
# the Web Server Flow, but it can also handle the flow for native 
# applications 
# The client_id and client_secret are copied from the API Access tab on 
# the Google APIs Console 
FLOW = OAuth2WebServerFlow(
    client_id='YOUR_CLIENT_ID', 
    client_secret='YOUR_CLIENT_SECRET', 
    scope='https://www.googleapis.com/auth/calendar', 
    user_agent='YOUR_APPLICATION_NAME/YOUR_APPLICATION_VERSION') 

# To disable the local server feature, uncomment the following line: 
# FLAGS.auth_local_webserver = False 

# If the Credentials don't exist or are invalid, run through the native client 
# flow. The Storage object will ensure that if successful the good 
# Credentials will get written back to a file. 
storage = Storage('calendar.dat') 
credentials = storage.get() 
if credentials is None or credentials.invalid == True: 
    credentials = run(FLOW, storage) 

# Create an httplib2.Http object to handle our HTTP requests and authorize it 
# with our good Credentials. 
http = httplib2.Http() 
http = credentials.authorize(http) 

# Build a service object for interacting with the API. Visit 
# the Google APIs Console 
# to get a developerKey for your own application. 
service = build(serviceName='calendar', version='v3', http=http, 
     developerKey='YOUR_DEVELOPER_KEY') 

और यह उत्पादन होता है:

Your browser has been opened to visit: 

    https://accounts.google.com/o/oauth2/auth? (auth url shortened) 

If your browser is on a different machine then exit and re-run this 
application with the command-line parameter 

    --noauth_local_webserver 

Traceback (most recent call last): 
    File "C:\Users\Desktop\Google Drive\Code\Python\Rooster\calendar.py", line 2, in <module> 
    import httplib2 
    File "C:\Python27\lib\site-packages\httplib2-0.7.6-py2.7.egg\httplib2\__init__.py", line 42, in <module> 
    import calendar 
    File "C:\Users\Desktop\Google Drive\Code\Python\Rooster\calendar.py", line 33, in <module> 
    credentials = run(FLOW, storage) 
    File "C:\Python27\lib\site-packages\google_api_python_client-1.0-py2.7.egg\oauth2client\util.py", line 120, in positional_wrapper 
    return wrapped(*args, **kwargs) 
    File "C:\Python27\lib\site-packages\google_api_python_client-1.0-py2.7.egg\oauth2client\tools.py", line 169, in run 
    credential = flow.step2_exchange(code, http=http) 
    File "C:\Python27\lib\site-packages\google_api_python_client-1.0-py2.7.egg\oauth2client\util.py", line 120, in positional_wrapper 
    return wrapped(*args, **kwargs) 
    File "C:\Python27\lib\site-packages\google_api_python_client-1.0-py2.7.egg\oauth2client\client.py", line 1128, in step2_exchange 
    http = httplib2.Http() 
AttributeError: 'module' object has no attribute 'Http' 

उत्तर

4

समस्या अपने रन निर्देशिका में वह यह है कि आपके पास calendar.py नाम की फ़ाइल है। जब Google का httplib2 मानक कैलेंडर मॉड्यूल आयात करना चाहता है तो उसे स्थानीय स्थान मिल जाता है। स्थानीय में यह आयात करने के लिए इसे निष्पादित करता है। लेकिन क्योंकि httplib2 अभी तक पूरी तरह से आयात नहीं किया गया है calendar.py कोड ठीक से काम नहीं कर रहा है। बस कैलेंडर.py का नाम बदलकर myCalendar.py जैसा करें।

+0

बहुत बहुत धन्यवाद, मैंने पहले ही कोशिश की थी, क्योंकि मुझे संदेह था कि समस्या होने के बावजूद, यह काम नहीं करेगा। मैं Aptana3 में कोडिंग कर रहा हूं और प्रोग्राम में फ़ाइल का नाम बदल चुका हूं। हालांकि, आपकी टिप्पणी पढ़ने और निर्देशिका की जांच करने के बाद यह दिखाई दिया कि Aptana संकलित पायथन फ़ाइलों को भी उत्पन्न करता है, इसलिए निर्देशिका में अभी भी एक अतिरिक्त कैलेंडर.py था। – Difusio

+1

यह Aptana नहीं है लेकिन मुझे लगता है कि अजगर। पायथन दुभाषिया संकलित संस्करण डिफ़ॉल्ट रूप से बनाता है। –

संबंधित मुद्दे