无法使用应用程序引擎通过API从Flask,odbc,freeTDS连接到MSSQL数据库

时间:2019-06-27 18:28:31

标签: python flask odbc freetds

我对所有这些Google App Engine和odbc FreeTDS都是陌生的。我需要使用应用程序引擎通过API从flask连接到MSSQL数据库。我不确定可以在odbcinst.ini中使用什么平台,还是应该将odbcinst.ini分别上传到云中。

如果我自己上传obdcinst.ini,则错误为00081 unable to connect the database。如果我在odbcinst.ini中回显dockerfile,则错误是 步骤12/16:ADD odbcinst.ini /etc/odbcinst.ini ADD failed: stat /var/lib/docker/tmp/docker-builder250249342/odbcinst.ini: no such file or directory 错误

dockerfile:

FROM gcr.io/google-appengine/python

# Create a virtualenv for dependencies. This isolates these packages from
# system-level packages.
# Use -p python3 or -p python3.7 to select python version. Default is version 2.
RUN virtualenv /env -p python3.7

# Setting these environment variables are the same as running
# source /env/bin/activate.
ENV VIRTUAL_ENV /env
ENV PATH /env/bin:$PATH

#Install FreeTDS and dependencies for PyODBC
RUN apt-get update && \
    apt-get install -y tdsodbc unixodbc-dev && \
    apt-get install freetds-dev freetds-bin tdsodbc -y && \
    apt install unixodbc-bin -y && \
    apt-get clean -y
#RUN odbcinst -i -d -f /etc/odbcinst.ini
RUN echo "[FreeTDS]\n\
Description = FreeTDS unixODBC Driver\n\
Driver = /usr/lib/x86_64-linux-gnu/odbc/libtdsodbc.so\n\
Setup = /usr/lib/x86_64-linux-gnu/odbc/libtdsS.so" >> /etc/odbcinst.ini
#ADD odbcinst.ini /etc/odbcinst.ini

# Copy the application's requirements.txt and run pip to install all
# dependencies into the virtualenv.
# Install any needed packages specified in requirements.txt
ADD requirements.txt requirements.txt
RUN pip install -r requirements.txt


# Copy the current directory contents into the container at /app
ADD algorithm_2.py algorithm_2.py
ADD main.py main.py

# Run app.py when the container launches
CMD ["python", "main.py"]

main.py:

@app.route('/v2/agent/<name>/<address>/<type>/<price>')
def Somefunction(name, address, type, price):

    import pyodbc

    con = pyodbc.connect('DRIVER={FreeTDS};'
                         'SERVER=xxxx.database.windows.net;'
                         'DATABASE=xxxx;'
                         'UID=xxxx;'
                         'PWD=xxxx;'
                         'TDS_Version = 8.0;')
    df_input = pd.read_sql(
        'SELECT xxxx
       ' FROM xxxx '
       ' LEFT JOIN xxxxx)
    con.commit()

app.yaml:

runtime: custom

#entrypoint: gunicorn -b :$PORT main:app

env: flex
manual_scaling:
  instances: 1

service: s2

obdcinst.ini:

[FreeTDS]
Description=FreeTDS Driver
Driver=/usr/lib/x86_64-linux-gnu/odbc/libtdsodbc.so
Setup=/usr/lib/x86_64-linux-gnu/odbc/libtdsS.so
TDS_Version = 8.0

如果有人可以帮助我,那将很棒。谢谢。

0 个答案:

没有答案