简体   繁体   中英

What do I fix this python error? self.stdin.write(input) TypeError: write() argument must be str, not bytes

I am trying to execute following code but it is not running. Error log pasted below. This issue is caused may be because of importing PG but I don't know how to resolve this.

import pandas as pd
from sqlalchemy import create_engine, MetaData, Table, select, engine
from sqlalchemy.orm import sessionmaker
import datetime
import cx_Oracle
import dateutil.relativedelta
import configparser
import sys, os
from boto3.s3.transfer import S3Transfer
import boto3
import pg

try:
    options = 'keepalives=1 keepalives_idle=200 keepalives_interval=200 keepalives_count=5'
    connection_string = "host=%s port=%s dbname=%s user=%s password=%s %s" % (
        'somehost', '8192', 'somedb', 'someuser', 'somepassword', options)
    print(connection_string)
    con = pg.connect(dbname=connection_string)
    print('Connected to Redshift.Connection Detail : %s' % con)

except Exception as e:
    print('Unable to Connect to Redshift')
    print(e.message)
    print('No')
    sys.exit(1)



C:\Users\olaa\Desktop\CWB> python .\my.py Traceback (most recent call last):   File ".\my.py", line 11, in <module>
    import pg   File "C:\Users\olaa\AppData\Local\Programs\Python\Python36\lib\site-packages\pg\__init__.py", line 1, in <module>
    from .core import (   File "C:\Users\olaa\AppData\Local\Programs\Python\Python36\lib\site-packages\pg\core.py", line 6, in <module>
    from . import glfw   File "C:\Users\olaa\AppData\Local\Programs\Python\Python36\lib\site-packages\pg\glfw.py", line 138, in <module>
    ['', '/usr/lib', '/usr/local/lib', 'C:/Users/olaa/AppData/Local/Programs/Python/Python36/Lib/site-packages/pg/'],
_g lfw_get_version)   File "C:\Users\olaa\AppData\Local\Programs\Python\Python36\lib\site-packages\pg\glfw.py", line 74, in _load_library
    version = version_check_callback(filename)   File "C:\Users\olaa\AppData\Local\Programs\Python\Python36\lib\site-packages\pg\glfw.py", line 130, in _glfw_get_versi on
    out = process.communicate(_to_char_p(filename))[0]   File "C:\Users\olaa\AppData\Local\Programs\Python\Python36\lib\subprocess.py", line 836, in communicate
    stdout, stderr = self._communicate(input, endtime, timeout)   File "C:\Users\olaa\AppData\Local\Programs\Python\Python36\lib\subprocess.py", line 1076, in _communicate
    self._stdin_write(input)   File "C:\Users\olaa\AppData\Local\Programs\Python\Python36\lib\subprocess.py", line 776, in _stdin_write
    self.stdin.write(input) TypeError: write() argument must be str, not bytes

Traceback (most recent call last):
  File "<string>", line 28, in <module>
EOFError: EOF when reading a line
import pg

This isn't a Postgres library. It's an OpenGL graphics library

Even if that import worked, it would fail at con = pg.connect( ...

You're trying to connect to Redshift / Postgres, so try one of the actual Postgres clients

In general, Python users want to use psycopg2 unless they have a strong reason to try another driver

https://wiki.postgresql.org/wiki/Python

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM