【发布时间】:2018-11-30 21:39:38
【问题描述】:
我正在尝试运行 Python(version 2.7.1') 脚本,我正在使用 pymysql 包 从 CSV 文件将表创建到数据库中.
它在我的本地系统中正常运行,但是,在 Google Cloud Dataflow 中将相同的脚本作为管道的一部分运行时会出现问题。
我的 Python 函数如下:
class charge_to_db(beam.DoFn):
def process(self, element):
import pymysql
with open(element, 'r') as f:
data = f.read().decode("UTF-8")
datalist = []
for line in data.split('\n'):
datalist.append(line.split(','))
db = pymysql.connect(host='IPaddress', user='root', password='mypassword', database='stack_model')
cursor = db.cursor()
cursor.execute("DROP TABLE IF EXISTS stack_convergence")
# create column names from the first line in fList
up = "upper_bnd"
primal = "primal"
d = "dualit"
gap = "gap_rel"
teta = "teta"
alpha = "alpha"
imba = "imba_avg"
price = "price_avg"
# create STUDENT table // place a comma after each new column except the last
queryCreateConvergenceTable = """CREATE TABLE stack_convergence(
{} float not null,
{} float not null,
{} float not null,
{} float not null,
{} float not null,
{} float not null,
{} float not null,
{} float not null )""".format(up, primal, d, gap, teta, alpha, imba, price)
cursor.execute(queryCreateConvergenceTable)
在云中运行此功能时,我收到以下错误:
RuntimeError: OperationalError: (2003, 'Can\'t connect to MySQL server on \'35.195.1.40\' (110 "Connection timed out")')
我不知道为什么会发生此错误,因为它在本地系统中正确运行,因此我可以从本地系统访问我的云 SQL 实例,但不能从云中的数据流访问。
为什么会出现这个错误?
【问题讨论】:
标签: python mysql google-cloud-platform google-cloud-dataflow google-cloud-sql