Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/kotlin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Google bigquery Pyodbc与BigQuery_Google Bigquery_Odbc_Pyodbc_Unixodbc - Fatal编程技术网

Google bigquery Pyodbc与BigQuery

Google bigquery Pyodbc与BigQuery,google-bigquery,odbc,pyodbc,unixodbc,Google Bigquery,Odbc,Pyodbc,Unixodbc,我试图让Pyodbc与googlebigquery一起工作。 我安装的ODBC管理器是unixodbc ubuntu Simba驱动程序的配置应该可以,因为SQL命令可以工作,我可以从那里执行查询 然而,当使用Pyodbc时,我被卡住了。 代码如下: import pyodbc dbname = 'testdb' driver_str = '{Simba ODBC Driver for Google BigQuery 64-bit}' cnxn = pyodbc.connect(driver=

我试图让Pyodbc与googlebigquery一起工作。 我安装的ODBC管理器是unixodbc ubuntu Simba驱动程序的配置应该可以,因为SQL命令可以工作,我可以从那里执行查询

然而,当使用Pyodbc时,我被卡住了。 代码如下:

import pyodbc

dbname = 'testdb'
driver_str = '{Simba ODBC Driver for Google BigQuery 64-bit}'
cnxn = pyodbc.connect(driver=driver_str, database=dbname)

c = conn.cursor()
c.execute('SELECT * FROM tablename')
print(c.fetchone())
它会产生以下错误:

Traceback (most recent call last):
  File "/home/virus/work/lutech/wind/usecase3/test_odbc.py", line 48, in <module>
    cnxn = pyodbc.connect(driver=driver_str, database=dbname)
pyodbc.OperationalError: ('08001', '[08001] [unixODBC][Simba][DSI] An error occurred while attempting to retrieve the error message for key \'UnableToEstConn\' and component ID 1: Could not open error message files - Check that "/home/virus/work/lutech/wind/simba/googlebigqueryodbc/lib/64/$(INSTALLDIR)/ErrorMessages/en-US/ODBCMessages.xml" or "/home/virus/work/lutech/wind/simba/googlebigqueryodbc/lib/64/$(INSTALLDIR)/ErrorMessages/ODBCMessages_en-US.xml" exists and are accessible. MessageParameters=["{[Catalog] [OAuthMechanism]}"] (-1) (SQLDriverConnect)')
我不明白它是什么意思,但它指的是Simba Error文件夹中的一个文件


有什么帮助吗?

我用一种非常密集的尝试和错误方法解决了这个问题。现在很清楚了。 我使用本地用户配置文件,以避免权限问题。在/etc/中的是空的

这是my.odbcinst.ini文件的内容:

$ cat .odbcinst.ini 

[ODBC Drivers]
Simba ODBC Driver for Google BigQuery 64-bit=Installed
[Simba ODBC Driver for Google BigQuery 64-bit]
Description=Simba ODBC Driver for Google BigQuery (64-bit)
Driver=<local user installation path>/simba/googlebigqueryodbc/lib/64/libgooglebigqueryodbc_sb64.so
这里是my.odbc.ini:

$ cat .odbc.ini 

[bigquery_odbc]
Driver=Simba ODBC Driver for Google BigQuery 64-bit
Catalog=<gcp project id>
OAuthMechanism=0
Email= <email service account>
KeyFilePath=<path to the json file downloaded when creating the service account>
在这里,您应该能够成功地执行 isql-v bigquery_odbc

现在,如果我尝试使用pyodbc进行连接,就会出现上面的错误。 首先修复配置文件中表示的安装路径以及指定的UTF编码

调用pyodbc时,它起作用了:

dataset_name = <bigquery dataset name>
DSN = 'bigquery_odbc'
conn_str = "DSN={}".format(DSN)
cnxn = pyodbc.connect(conn_str, autocommit=True) # DO NOT forget autocommit param
cursor = cnxn.cursor()
cursor.execute('select * from {}.table;'.format(dataset_name))
print(cursor.fetchone())
我在这个配置上挣扎了很多。希望它能帮助别人

dataset_name = <bigquery dataset name>
DSN = 'bigquery_odbc'
conn_str = "DSN={}".format(DSN)
cnxn = pyodbc.connect(conn_str, autocommit=True) # DO NOT forget autocommit param
cursor = cnxn.cursor()
cursor.execute('select * from {}.table;'.format(dataset_name))
print(cursor.fetchone())