Spaces:
Running
Running
File size: 4,028 Bytes
b5fb8d2 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
#!/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()
|