Pysql connection timing out

Trying to connect to our external MySql database, running the sample code in the documentation, we’re getting a timeout. My partner has the Anvil IP address (52.56.203.177) in his whitelist, so not sure what could be causing this, ideas welcome.

import anvil.email
import anvil.users
import anvil.tables as tables
import anvil.tables.query as q
from anvil.tables import app_tables
import anvil.server
import pymysql

@anvil.server.callable
def connect():
  connection = pymysql.connect(host='xx.xx.xxx.xxx',
                              port=3306,
                              user='xxxxxx',
                              password='xxxxx',
                              database='xxxx)
  return connection

@anvil.server.callable
def TestConnection():
  conn = anvil.server.call('connect')
  print(conn)

The examples for connecting to external databases are primarily showing connection to Postgres databases, however, I understand the connection to MySql should be very similar. Per my previous post, I have tried executing the exact code from the single Mysql example - to no avail. I have tested my credentials, etc., from MySQLWorkbench and it connects just fine, so I believe it safe to assume that is not the problem.

MySQLWorkbench is hitting the external database with my client IP address, which is in that machine’s whitelist. pysql is not available on the client, so I assume when my anvil server code executes, it’s trying to connect to the external database from the anvil server’s IP address… .which we have also added to the external database’s whitelist

At this juncture I am out of options and dead in the water with what to try next. ANY ideas are welcomed.

Merged the topics. I hope a solution is found very soon. If I had any insights I would help of course.

One thing I would recommend is trying the code as a simple python script on your local machine.
This way you can narrow down the bug to its most simple parts.

If you get to a point when you can connect to the server on your local machine with the code snippet then you can see what changes if you run the code in anvil’s server module.

You also may want to check you whitelisted the correct IP address(es). See this post

Hi @dconnell,

As @stucork’s link says, connections from Anvil can emerge from any of a pool of IP addresses – and your app may be connecting from one of the other ones. Drop a line to support@anvil.works to get the current list.

It sounds like this issue has slowed you down. If you’d like a guaranteed one-working-day response to questions like this, we offer support plans with a guaranteed response from an expert! Otherwise, you’re welcome to continue asking the forum, but remember that this community doesn’t have an SLA :slight_smile: