Spaces:
Running
Running
| #!/usr/bin/env python3 | |
| """ | |
| Fix Google verification issue for OAuth | |
| """ | |
| import os | |
| import json | |
| from google.oauth2.credentials import Credentials | |
| from google_auth_oauthlib.flow import InstalledAppFlow | |
| from google.auth.transport.requests import Request | |
| # Configuration | |
| SCOPES = ['https://www.googleapis.com/auth/drive.file'] | |
| CREDENTIALS_FILE = 'credentials.json' | |
| TOKEN_FILE = 'token.json' | |
| def fix_verification_issue(): | |
| """Fix Google verification issue""" | |
| print("π§ Fixing Google Verification Issue") | |
| print("=" * 50) | |
| print("π The issue is that your app needs to be in 'Testing' mode") | |
| print(" and you need to be added as a test user.") | |
| print() | |
| print("π§ Manual Fix Required:") | |
| print("1. Go to: https://console.cloud.google.com/") | |
| print("2. APIs & Services β OAuth consent screen") | |
| print("3. Make sure 'Publishing status' is set to 'Testing'") | |
| print("4. Scroll down to 'Test users' section") | |
| print("5. Click 'Add Users'") | |
| print("6. Add your email: [email protected]") | |
| print("7. Save the changes") | |
| print() | |
| print("π Alternative: Change User Type to Internal") | |
| print(" (If you have a Google Workspace account)") | |
| print() | |
| # Check if credentials exist | |
| if not os.path.exists(CREDENTIALS_FILE): | |
| print(f"β {CREDENTIALS_FILE} not found!") | |
| return False | |
| # Delete old token file | |
| if os.path.exists(TOKEN_FILE): | |
| print(f"ποΈ Removing old token file: {TOKEN_FILE}") | |
| os.remove(TOKEN_FILE) | |
| print("β Ready to test after you add yourself as a test user") | |
| print() | |
| # Ask user if they've completed the steps | |
| response = input("Have you added yourself as a test user? (y/n): ").strip().lower() | |
| if response == 'y': | |
| print("\nπ§ͺ Testing authentication...") | |
| try: | |
| # Try authentication | |
| flow = InstalledAppFlow.from_client_secrets_file(CREDENTIALS_FILE, SCOPES) | |
| creds = flow.run_local_server(port=0) | |
| print("β Authentication successful!") | |
| # Save credentials | |
| with open(TOKEN_FILE, 'w') as token: | |
| token.write(creds.to_json()) | |
| print(f"β Credentials saved to {TOKEN_FILE}") | |
| # Test Google Drive access | |
| print("\nπ§ͺ Testing Google Drive access...") | |
| from googleapiclient.discovery import build | |
| service = build('drive', 'v3', credentials=creds) | |
| results = service.files().list(pageSize=1, fields="files(id, name)").execute() | |
| files = results.get('files', []) | |
| print("β Google Drive access successful!") | |
| print(f" Found {len(files)} file(s) in your Drive") | |
| return True | |
| except Exception as e: | |
| error_msg = str(e).lower() | |
| if "access_denied" in error_msg or "verification" in error_msg: | |
| print("β Still getting verification error") | |
| print("π‘ Make sure you:") | |
| print(" 1. Added yourself as a test user") | |
| print(" 2. Set publishing status to 'Testing'") | |
| print(" 3. Saved all changes") | |
| return False | |
| else: | |
| print(f"β Authentication failed: {e}") | |
| return False | |
| else: | |
| print("π‘ Please complete the steps above and run this script again") | |
| return False | |
| def main(): | |
| """Main function""" | |
| print("π Google Verification Fix for RAG System") | |
| print("=" * 50) | |
| if fix_verification_issue(): | |
| print("\nπ Verification issue fixed!") | |
| print("β You can now run: python setup_google_drive_rag.py") | |
| else: | |
| print("\nβ Please complete the manual steps above") | |
| if __name__ == "__main__": | |
| main() | |