import requests import re def register_gitea_user(): # First get the CSRF token from the registration page session = requests.Session() # Get registration page url = "https://git.mtrcompute.com/user/sign_up" response = session.get(url) # Extract CSRF token csrf_token = None match = re.search(r'csrfToken:\s*\'([^\']+)\'', response.text) if match: csrf_token = match.group(1) else: # Try another pattern match = re.search(r'name="csrf_token"\s+value="([^"]+)"', response.text) if match: csrf_token = match.group(1) if not csrf_token: print("Could not find CSRF token") return False print(f"CSRF Token: {csrf_token}") # Prepare registration data data = { 'user_name': 'jleu3482', 'email': 'slclabs@gmail.com', 'password': 'jleu1212', 'retype': 'jleu1212', 'csrf_token': csrf_token } # Submit registration headers = { 'Content-Type': 'application/x-www-form-urlencoded', 'Referer': url } response = session.post(url, data=data, headers=headers, allow_redirects=False) print(f"Status Code: {response.status_code}") print(f"Headers: {response.headers}") if response.status_code == 302: print("Registration successful! Redirecting...") return True else: print(f"Registration failed. Response: {response.text[:500]}") return False if __name__ == "__main__": register_gitea_user()