![](/img/trans.png)
[英]Music21 Midi Error: type object '_io.StringIO' has no attribute 'StringIO'. How to fix it?
[英]How do I correct stringIO() has no attribute error in aws lambda?
我有一個查詢,我試圖將它發送到STDIN
然后發送到一個 csv 文件,並且復制命令正在失敗。 當我調用io.StringIO()
時它似乎倒下了
我收到的錯誤是: Error connecting to postgres instance '_io.StringIO' object has no attribute 'getValue'
我的代碼如下所示:
import psycopg2
from io import StringIO
import boto3
bucket = 'my_s3_bucket'
filename = 'test_data'
s3_resource = boto3.resource('s3')
conn = psycopg2.connect(host='localhost'
, port='5432'
, dbname='billing_test'
, user='postgres'
, password='password!')
cur = conn.cursor()
sql_query = "SELECT\
* from public.customers\
limit 1"
#cur.execute(sql_query)
#records = cur.fetchall()
#print(records)
query = '''COPY ({}) TO STDIN csv header'''.format(sql_query)
file = StringIO()
cur.copy_expert(query, file)
s3_resource.Object(bucket, f'{filename}.csv').put(Body=file.getValue())
cur.close()
conn.close()
您應該閱讀文檔, help()
是您在交互式終端中最好的朋友:
import io
help(io.StringIO)
... | getvalue(self, /) | Retrieve the entire contents of the object. | ...
您應該使用getvalue()
而不是getValue()
s3_resource.Object(bucket, f'{filename}.csv').put(Body=file.getvalue())
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.