Forums

Connecting to Oracle Database for Web App

Hi, I was hoping someone could help. I'm trying to connect to an Oracle Database through a bottle app so I can pull information for the website we can run on pythonanywhere. When I try to run it though it cannot find the files I installed and throws an error. I was hoping someone had done this or could try to step me through the process. Thanks!

Hmm, we don't have a step-by-step guide but perhaps we could help you work through the errors you're getting. One thing that does occur to me, though, is that you currently have a free PythonAnywhere account. Free accounts are limited to HTTP and HTTPS access to external sites, and they need to be on our whitelist of official public APIs. I don't think the Oracle protocol is HTTP/HTTPS based, and of course your server won't be on the whitelist.

Python connectivity with ATP DB is working fine on local machine using the below code

import oracledb

Define connection details connection = oracledb.connect( user="admin", # Replace with your Oracle ATP username password="XXXX666", # Replace with your Oracle ATP password dsn="tcps://adb.uk-london-1.oraclecloud.com:1522/gffad144248701c_mani.adb.oraclecloud.com", # DSN for Oracle ATP

config_dir="C:\oracle\Wallet_mani.zip", # Path to your wallet directory

wallet_location="C:\oracle\Wallet_mani", # Path to your wallet wallet_password="XXXX666" # Optional: Replace with wallet password if required )

Test the connection try: print("Connection successful!") with connection.cursor() as cursor:

Example query

cursor.execute("SELECT SYSDATE||' Hum Tum Here ' FROM DUAL") for row in cursor: print("Database Date:", row[0]) except oracledb.DatabaseError as e: print(f"An error occurred: {e}") finally: if 'connection' in locals() and connection: connection.close()

Same code is not working at pythonanywhere.com

upload wallet file into Pythonanywhere.com home directory and update the code to fetch the directy which is unziped.

You would not be able to connect to the oracle database from a free account as only http(s) connections to sites from allow-list are permitted.