11#!/usr/bin/env python3
2- import json
32import base64
3+ import json
4+
45import requests
56
67# Load config
7- with open (' config.json' ) as f :
8+ with open (" config.json" ) as f :
89 config = json .load (f )
910
10- reddit = config [' reddit' ]
11+ reddit = config [" reddit" ]
1112
1213print ("=" * 50 )
1314print ("Reddit Auth Debug" )
1920print (f"Client Secret first 4: { reddit ['client_secret' ][:4 ]} ..." )
2021
2122# Check for common issues
22- if len (reddit [' client_id' ]) > 20 :
23+ if len (reddit [" client_id" ]) > 20 :
2324 print ("⚠️ Client ID seems too long - might be using secret as ID?" )
24- if len (reddit [' client_secret' ]) < 20 :
25+ if len (reddit [" client_secret" ]) < 20 :
2526 print ("⚠️ Client Secret seems too short - might be using ID as secret?" )
2627
2728# Test manual auth
2829print ("\n Testing manual authentication..." )
2930auth = base64 .b64encode (f"{ reddit ['client_id' ]} :{ reddit ['client_secret' ]} " .encode ()).decode ()
30- headers = {
31- "Authorization" : f"Basic { auth } " ,
32- "User-Agent" : f"ModlogWikiPublisher/1.0 by /u/{ reddit ['username' ]} "
33- }
34- data = {
35- "grant_type" : "password" ,
36- "username" : reddit ['username' ],
37- "password" : reddit ['password' ]
38- }
39-
40- response = requests .post (
41- "https://www.reddit.com/api/v1/access_token" ,
42- headers = headers ,
43- data = data
44- )
31+ headers = {"Authorization" : f"Basic { auth } " , "User-Agent" : f"ModlogWikiPublisher/1.0 by /u/{ reddit ['username' ]} " }
32+ data = {"grant_type" : "password" , "username" : reddit ["username" ], "password" : reddit ["password" ]}
33+
34+ response = requests .post ("https://www.reddit.com/api/v1/access_token" , headers = headers , data = data )
4535
4636print (f"\n Response Status: { response .status_code } " )
4737print (f"Response Headers: { dict (response .headers )} " )
5343 print ("2. Client ID = the string under 'personal use script' (shorter)" )
5444 print ("3. Client Secret = the 'secret' field (longer)" )
5545 print ("4. Make sure the app type is 'script' not 'web app'" )
56- print ("5. Username should be just 'Bakerboy448' not 'u/Bakerboy448'" )
46+ print ("5. Username should be just 'Bakerboy448' not 'u/Bakerboy448'" )
0 commit comments