如果您对将psycopg2与Lambda一起使用以更新Redshift感兴趣,那么本文将是一篇不错的选择,我们将为您详在本文中,您将会了解到关于将psycopg2与Lambda一起使用以更新Redsh
如果您对将psycopg2与Lambda一起使用以更新Redshift感兴趣,那么本文将是一篇不错的选择,我们将为您详在本文中,您将会了解到关于将psycopg2与Lambda一起使用以更新Redshift的详细内容,我们还将为您解答Python的相关问题,并且为您提供关于Django / Python入门:执行python manage.py syncdb时出错-找不到psycopg2、Django,mod_wsgi,psycopg2错误configuration:加载psycopg2模块时出错:没有名为_psycopg的模块、Python / psycopg2中的优美主键错误处理、python install psycopg2-2.6.2 error的有价值信息。
本文目录一览:- 将psycopg2与Lambda一起使用以更新Redshift(Python)
- Django / Python入门:执行python manage.py syncdb时出错-找不到psycopg2
- Django,mod_wsgi,psycopg2错误configuration:加载psycopg2模块时出错:没有名为_psycopg的模块
- Python / psycopg2中的优美主键错误处理
- python install psycopg2-2.6.2 error
将psycopg2与Lambda一起使用以更新Redshift(Python)
我正在尝试使用python从Lambda函数更新Redshift。为此,我尝试合并2个代码片段。当我分别运行它们时,这两个片段都起作用。
- 从PyDev for Eclipse更新Redshift
import psycopg2 conn_string = "dbname=''name'' port=''0000'' user=''name'' password=''pwd'' host=''url''" conn = psycopg2.connect(conn_string) cursor = conn.cursor() cursor.execute("UPDATE table SET attribute=''new''") conn.commit() cursor.close()
- 接收上传到S3存储桶的内容(Lambda上提供预构建的模板)
from __future__ import print_function import json import urllib import boto3 print(''Loading function'') s3 = boto3.client(''s3'') def lambda_handler(event, context): #print("Received event: " + json.dumps(event, indent=2)) # Get the object from the event and show its content type bucket = event[''Records''][0][''s3''][''bucket''][''name''] key = urllib.unquote_plus(event[''Records''][0][''s3''][''object''][''key'']).decode(''utf8'') try: response = s3.get_object(Bucket=bucket, Key=key) print("CONTENT TYPE: " + response[''ContentType'']) return response[''ContentType''] except Exception as e: print(e) print(''Error getting object {} from bucket {}. Make sure they exist and your bucket is in the same region as this function.''.format(key, bucket)) raise e
由于这两个段都起作用,因此我尝试将它们组合在一起,以便在将文件上传到s3时可以更新Redshift:
from __future__ import print_function import json import urllib import boto3 import psycopg2 print(''Loading function'') s3 = boto3.client(''s3'') def lambda_handler(event, context): #print("Received event: " + json.dumps(event, indent=2)) # Get the object from the event and show its content type bucket = event[''Records''][0][''s3''][''bucket''][''name''] key = urllib.unquote_plus(event[''Records''][0][''s3''][''object''][''key'']).decode(''utf8'') conn_string = "dbname=''name'' port=''0000'' user=''name'' password=''pwd'' host=''url''" conn = psycopg2.connect(conn_string) cursor = conn.cursor() cursor.execute("UPDATE table SET attribute=''new''") conn.commit() cursor.close() try: response = s3.get_object(Bucket=bucket, Key=key) print("CONTENT TYPE: " + response[''Body''].read()) return response[''Body''].read() except Exception as e: print(e) print(''Error getting object {} from bucket {}. Make sure they exist and your bucket is in the same region as this function.''.format(key, bucket)) raise e
由于我使用的是外部库,因此需要创建一个部署程序包。我创建了一个新文件夹(lambda_function1)并将我的.py文件(lambda_function1.py)移至该文件夹。我运行以下命令在该文件夹中安装psycopg2:
pip install psycopg2 -t \lambda_function1
我收到以下反馈:
Collecting psycopg2 Using cached psycopg2-2.6.1-cp34-none-win_amd64.whl Installing collected packages: psycopg2 Successfully installed psycopg2-2.6.1
然后,我压缩目录的内容。并将该zip文件上传到我的lambda函数。当我将文档上传到功能监视的存储桶时,我的cloudwatch日志中收到以下错误:
Unable to import module ''lambda_function1'': No module named _psycopg
当我在库中查找时,唯一名为“ _psycopg”的是“ _psycopg.pyd”。
是什么导致此问题?当我使用3.4时,Lambda使用Python
2.7是否重要?在Windows计算机上压缩文件内容是否重要?有没有人能够从lambda成功连接到Redshift?
答案1
小编典典为了使其正常工作,您需要psycopg2
使用静态链接libpq.so
库进行构建。查看此仓库https://github.com/jkehler/awslambda-
psycopg2。它已经构建了psycopg2软件包并说明了如何自行构建。
回到您的问题:
是什么导致此问题?
psycopg2
需要使用用于Linux的静态链接库来构建编译器。
当我使用3.4时,Lambda使用Python 2.7是否重要?
是的,lambda仅支持2.7版本。只需创建虚拟环境并在其中安装所有必需的软件包即可。
在Windows计算机上压缩文件内容是否重要?
只要您压缩的所有库都可以在Linux上运行,它就不会
有没有人能够从lambda成功连接到Redshift?
是。
Django / Python入门:执行python manage.py syncdb时出错-找不到psycopg2
我使用Macports安装了Pythong2.6,psycopg2和pgAdmin3。我的settings.py是:
DATABASE_ENGINE = 'postgresql_psycopg2' # 'postgresql_psycopg2','postgresql','mysql','sqlite3' or 'oracle'.
DATABASE_NAME = 'mysite' # Or path to database file if using sqlite3.
DATABASE_USER = 'postgres' # Not used with sqlite3.
DATABASE_PASSWORD = '' # Not used with sqlite3.
DATABASE_HOST = '' # Set to empty string for localhost. Not used with sqlite3.
DATABASE_PORT = '' # Set to empty string for default. Not used with sqlite3.
运行python manage.py syncdb时遇到的错误是:
Traceback (most recent call last):
File "manage.py",line 11,in <module>
execute_manager(settings)
File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/django/core/management/__init__.py",line 362,in execute_manager
utility.execute()
File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/django/core/management/__init__.py",line 303,in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/django/core/management/base.py",line 195,in run_from_argv
self.execute(*args,**options.__dict__)
File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/django/core/management/base.py",line 221,in execute
self.validate()
File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/django/core/management/base.py",line 249,in validate
num_errors = get_validation_errors(s,app)
File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/django/core/management/validation.py",line 22,in get_validation_errors
from django.db import models,connection
File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/django/db/__init__.py",line 41,in <module>
backend = load_backend(settings.DATABASE_ENGINE)
File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/django/db/__init__.py",line 17,in load_backend
return import_module('.base','django.db.backends.%s' % backend_name)
File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/django/utils/importlib.py",line 35,in import_module
__import__(name)
File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/django/db/backends/postgresql_psycopg2/base.py",in <module>
raise ImproperlyConfigured("Error loading psycopg2 module: %s" % e)
django.core.exceptions.ImproperlyConfigured: Error loading psycopg2 module: No module named psycopg2
请注意,我是这方面的入门者。我本来是PHP专家,正在为一个小型个人项目试用Python。我需要“打开” Postgres吗?
另外,当我使用sudo python manage.py runserver 8080时,出现此错误:
Validating models...
Unhandled exception in thread started by <function inner_run at 0x1242670>
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/django/core/management/commands/runserver.py",line 48,in inner_run
self.validate(display_num_errors=True)
File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/django/core/management/base.py",in <module>
raise ImproperlyConfigured("Error loading psycopg2 module: %s" % e)
django.core.exceptions.ImproperlyConfigured: Error loading psycopg2 module: No module named psycopg2
请指导我。任何答复将不胜感激。
谢谢,
Django,mod_wsgi,psycopg2错误configuration:加载psycopg2模块时出错:没有名为_psycopg的模块
我有一个在Apache下运行的Django 1.5,Python 2.7站点,在CentOS 6.4服务器上使用mod_wsgi。
我已经使用Django 1.6和Python 3.3重build了这个站点。 将其部署到同一台服务器,并更改httpd.conf中的path我得到的主题错误。 这个新的安装按照预期使用./manage.py runserver。
这里是httpd.conf中的两个Wsgi定义:
WsgiScriptAlias / /home/ccdgen/CCDGEN2/apache/wsgi.py WsgiPythonPath /home/ccdgen/CCDGEN2/ccdgen/ccdgen:/home/ccdgen/CCDGEN2/ccdgen:/home/ccdgen/CCDGEN2/lib/python3.3/site-packages <Directory /home/ccdgen/CCDGEN2/ccdgen> <Files wsgi.py> Order allow,deny Allow from all </Files> </Directory> #WsgiScriptAlias /ccdgen /home/ccdgen/CCDGEN/apache/wsgi.py #WsgiPythonPath /home/ccdgen/CCDGEN/mlhim/ccdgen:/home/ccdgen/CCDGEN/mlhim:/home/ccdgen/CCDGEN/lib/python2.7/site-packages #<Directory /home/ccdgen/CCDGEN/mlhim> # <Files wsgi.py> # Order allow,deny # Allow from all # </Files> #</Directory>
wsgi.py文件在两个安装上是相同的:
MysqL错误 – #1932 – 表''PHPmyadmin.pma用户configuration''在引擎中不存在
的.htaccess。 拒绝根目录,允许特定的子文件夹。 可能?
运行没有扩展名的PHP,而不使用mod_rewrite?
无法访问本地networking上的wamp服务器
重写规则的速度?
import os os.environ.setdefault("DJANGO_SETTINGS_MODULE","mlhim.settings") from django.core.wsgi import get_wsgi_application application = get_wsgi_application()
有任何想法吗? 明显的疏忽? 谢谢
在Amazon Ec2上为apache用户设置pathvariables
在Windows Apache SimpleSAMLPHP安装
在此服务器上找不到cURL请求的url/api/process.PHP
Magento:Lighttpd vs Nginx
PHP脚本的多个实例不会在同一个浏览器中从同一个URL同时加载
最近我有这个问题:
ImproperlyConfigured: Error loading psycopg2 module: No module named _psycopg
…这个命令是答案:
sudo apt-get install libapache2-mod-wsgi-py3
参考:
http://python.6.x6.nabble.com/ImproperlyConfigured-Error-loading-psycopg2-module-No-module-named-psycopg-td5044145.html
试试这些命令Debian,Ubuntu
sudo apt-get install python-dev sudo apt-get install libpq-dev
对于RedHat Enterprise,Fedora,CentOS
sudo yum install python-devel sudo yum install postgresql-libs
然后安装psycopg2
pip install psycopg2
问题是mod_wsgi是为Python 2.7编译的,需要为Python 3.3重新编译。 我没有找到一个新的mod_wsgi作为一个包,所以我重新编译它。
由于Python 3是在CentOS 6.4上进行备用安装的,因此配置在生成良好的Makefile时很困难,甚至可以传递–with-python选项。 从python3.3-config –cflags和–ldflags选项获得信息后,我需要编辑一下Makefile。
HTH某人在未来。
正如已经提到的,mod_wsgi没有被编译为python 3.一个选择是使用软件集合和/或去与Nginx和“pip install uwsgi”,这节省了大量的编译和运行自定义软件包。
总结
以上是小编为你收集整理的Django,mod_wsgi,psycopg2错误configuration:加载psycopg2模块时出错:没有名为_psycopg的模块全部内容。
如果觉得小编网站内容还不错,欢迎将小编网站推荐给好友。
Python / psycopg2中的优美主键错误处理
使用Python 2.7和
在[150]中:psycopg2。 版本 Out [150]:“ 2.4.2(dt dec pq3 ext)”
我有一个简单的python脚本,用于处理事务并将数据写入数据库。有时有一个插入违反我的主键。很好,我只希望它忽略该记录并继续愉快地进行下去。我遇到的问题是psycopg2主键错误正在中止整个事务块,并且错误失败后所有插入。这是一个示例错误
ERROR: duplicate key value violates unique constraint "encounter_id_pkey"
DETAIL: Key (encounter_id)=(9012235) already exists.
这是在下一个插入。不违反。
Inserting: 0163168~9024065
ERROR: current transaction is aborted,commands ignored until end of transaction block
每个插入都会重复出现第二个错误。这是一个简化的循环。我正在遍历一个熊猫数据框,但是可能是任何循环。
conn = psycopg2.connect("dbname='XXXX' user='XXXXX' host='XXXX' password='XXXXX'")
cur = conn.cursor()
for i,val in df2.iteritems():
try:
cur = conn.cursor()
cur.execute("""insert into encounter_id_table (
encounter_id,current_date )
values
(%(create_date)s,%(encounter_id)s ) ;""",'encounter_id':i.split('~')[1],'create_date': datetime.date.today() })
cur.commit()
cur.close()
except Exception,e:
print 'ERROR:',e[0]
cur.close()
conn.close()
同样,基本思路是妥善处理错误。在皇家海军纳尔逊海军上将的格言中:“该死的演习直接针对他们”。我以为该死的错误直指它们。”我想通过在每个插入上打开一个游标,我将重置事务块。我不想仅由于主键错误而不必重置连接。有什么我只是想念的吗?
在此先感谢您的宝贵时间。
python install psycopg2-2.6.2 error
却少依赖文件
解决方法:
yum install postgresql-devel*
关于将psycopg2与Lambda一起使用以更新Redshift和Python的问题我们已经讲解完毕,感谢您的阅读,如果还想了解更多关于Django / Python入门:执行python manage.py syncdb时出错-找不到psycopg2、Django,mod_wsgi,psycopg2错误configuration:加载psycopg2模块时出错:没有名为_psycopg的模块、Python / psycopg2中的优美主键错误处理、python install psycopg2-2.6.2 error等相关内容,可以在本站寻找。
本文标签: