Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/windows/17.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
Python连接到AWS Athena抛出错误_Python_Windows_Python 2.7_Amazon Web Services_Amazon Athena - Fatal编程技术网

Python连接到AWS Athena抛出错误

Python连接到AWS Athena抛出错误,python,windows,python-2.7,amazon-web-services,amazon-athena,Python,Windows,Python 2.7,Amazon Web Services,Amazon Athena,我试图通过Python 2.7.13运行AWS Athena SQL查询,并遵循以下两个选项,但在这两种情况下,获取“Python.exe停止工作”错误。 我是python新手,非常感谢您的帮助 选项1:尝试使用Pyathenajdbc >>> from pyathenajdbc import connect >>> import pandas as pd >>> conn = connect(access_key='<acess_

我试图通过Python 2.7.13运行AWS Athena SQL查询,并遵循以下两个选项,但在这两种情况下,获取“Python.exe停止工作”错误。 我是python新手,非常感谢您的帮助

选项1:尝试使用Pyathenajdbc

>>> from pyathenajdbc import connect

>>> import pandas as pd

>>> conn = connect(access_key='<acess_key>',
               secret_key='<secret_key>',
               s3_staging_dir='s3://Test/',
               region_name='<region_name>',
               jvm_path='C:\\Program Files (x86)\\Java\\jre6\\bin\\client\\jvm.dll')

>>> df = pd.read_sql("select * from test.test45 LIMIT 1", conn)
>>来自pyathenajdbc导入连接
>>>作为pd进口熊猫
>>>连接=连接(访问键=)

使用Microsoft Visual studio进行Python调试时出现错误消息


python.exe中0x00170000处未处理的异常:0xC0000005:访问冲突。

JayDeBeApi太复杂,无法使用Athena JDBC进行调整,PyAthenajdbc更易于使用。 这就是我如何使用它,它就像一个魅力

宣言 用法
-非常感谢您的输入,但是我得到“python.exe已停止工作”即使在这段代码中也会出现错误。在运行脚本之前,我不确定是否丢失了任何参数或系统变量?我明白了。我使用的是Gnu/Linux操作系统,因此我从未遇到过该错误。但是,我做过一些研究,显然这个问题可能与各种原因有关。你能发布错误的屏幕截图吗?也许其他人可以帮助你?根据请求,在问题jpype中添加了错误截图。\u jexception.RuntimeException pyraisable:java.lang.RuntimeException:Class com.amazonaws.athena.jdbc.AthenaDriver未找到PyAthenaJDBC的创建者建议使用基于最新发布的boto SDK的其他模块:以下是类似的线程,可能与您的应用程序有关导入或者您可能对pandas版本有问题?pandas pip安装PyAthenaJDBC[pandas]>=0.19.0(参考)我尝试了您不使用pandas的代码,但仍然出现相同的错误。在您关于清理导入的评论中,我安装了“Pyflakes”并试图找出如何在代码中实现以进行清理。还注意到在错误屏幕截图中,应用程序版本为0.0.0.0而不是2.7.13,不确定这是否会导致任何错误。但是,cmd提示符中的Python-V返回的版本为2.7.13。有什么想法吗?如果您是Python新手,除非绝对必须。
import os
import configparser
import pyathenajdbc


# Get aws credentials 
aws_config_file = '~/.aws/config'

Config = configparser.ConfigParser()
Config.read(os.path.expanduser(aws_config_file))

access_key_id = Config['default']['aws_access_key_id']
secret_key_id = Config['default']['aws_secret_access_key']

BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
log_path = BASE_DIR + "/lib/static/queries.log"

class PyAthenaLoader():    
    def connecti(self):
        self.conn = pyathenajdbc.connect(
            s3_staging_dir="s3://athena",
            access_key=access_key_id,
            secret_key=secret_key_id,
            region_name="us-east-1",
            log_path=log_path,

        )

    def databases(self):
        dbs = self.query("show databases;")
        return dbs

    def tables(self, database):
        tables = self.query("show tables in {0};".format(database))
        return tables


    def query(self, req):
        self.connecti()

        try:
            with self.conn.cursor() as cursor:
                cursor.execute(req)
                res = cursor.fetchall()
        except Exception as X:
            return X
        finally:
            self.conn.close()
        return res
athena = PyAthenaLoader()
res = athena.query('SELECT * from shadow.sales;')
print(res)