denisenkom / pytds

Python DBAPI driver for MSSQL using pure Python TDS (Tabular Data Stream) protocol implementation

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

gaierror(-2, 'Name or service not known') when try to connect to db

LingboTang opened this issue · comments

How I use pytds is like this:

import pytds as db_module

def tryConnect():

    db_conn = {
          'dsn': 'datahost\myplace',
          'database': 'dev',
          'user': 'dwapp',
          'password': '****'
     }

    db = db_module.connect(**db_conn)

And I'm getting:

Cannot connect to server 'datahost': [Errno -2] Name or service not known, gaierror(-2, 'Name or service not known')

The code snippet works locally because I have set datahost in my /etc/hosts, but when I running it on docker, even if I manually add the datahost to docker using docker run -i --add-host before running this test, I still got this error. I know this error is related to the environment, but is there anything else I left? @denisenkom any help?

I am not very familiar with docker. You can try using real host name instead.