UnicodeEncodeError: 'ascii' codec can't encode characters in position 1-2: ordinal not in range(128)

python3 execute UnicodeEncodeError: 'ascii' codec can't encode characters in position 1-2: ordinal not in range(128)

当使用python 3.6版本爬取网页中文数据插入oracle时有可能报这个错误,这是由网页编码引起的,通过设置环境变量即可解决,如下图所示 SIMPLIFIED CHINESE_CHINA.AL32UTF8,当然这个是跟你数据库的编码一致的。

UnicodeEncodeError: 'ascii' codec can't encode characters in position 1-2: ordinal not in range(128)_第1张图片

 

linux(redhat6.5)下:cx_Oracle.DatabaseError: DPI-1047: 64-bit Oracle Client library cannot be load:

需要安装64位的oracle的客户端:oracle-instantclient11.2-basic-11.2.0.4.0-1.x86_64.rpm

以上是我11GR2的安装包,这个包直接安装就可以了,不需要依赖其他包,安装包资源在CSDN上有相关资源。

Oracle Instant Client RPM¶

To run ODPI-C applications with Oracle Instant Client RPMs:

  1. Download an Oracle 18, 12, or 11.2 “Basic” or “Basic Light” RPM: 64-bit or 32-bit, matching your application architecture.

  2. Install the downloaded RPM with sudo or as the root user. For example:

    sudo yum install oracle-instantclient12.2-basic-12.2.0.1.0-1.x86_64.rpm
    

    Yum will automatically install required dependencies, such as libaio.

  3. If there is no other Oracle software on the machine that will be impacted, permanently add Instant Client to the runtime link path. For example, with sudo or as the root user:

    sudo sh -c "echo /usr/lib/oracle/12.2/client64/lib > /etc/ld.so.conf.d/oracle-instantclient.conf"
    sudo ldconfig
    

    Alternatively, set the environment variable LD_LIBRARY_PATH to the appropriate directory for the Instant Client version. For example:

    export LD_LIBRARY_PATH=/usr/lib/oracle/12.2/client64/lib:$LD_LIBRARY_PATH
    
  4. If you intend to co-locate optional Oracle configuration files such as tnsnames.ora, sqlnet.ora or oraaccess.xml with Instant Client, then create a network/admin subdirectory under lib/, if it does not exist. For example:

    sudo mkdir -p /usr/lib/oracle/12.2/client64/lib/network/admin
    

    This is the default Oracle configuration directory for applications linked with this Instant Client.

    Alternatively, Oracle configuration files can be put in another, accessible directory. Then set the environment variable TNS_ADMIN to that directory name.

  5. 不设置环境变量,那么运行还是会报错,只设置第三步,root用户可以执行,但是crontab用户执行python脚本还是会报错

 

 

 

另外一个错误就是使用PIP 安装相关包报错,pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available. 

通过rpm -qa |grep openssl 发现只有一个包openssl-1.0.1e-15.el6.x86_64,缺少openssl-devel相关包,所以需要安装openssl-devel。这个安装包有很多依赖包,最好通过yum命令安装,如果需要用rpm安装,可以从我这个下载资源里面下载,连接如下:

https://download.csdn.net/download/u012209894/10750341

如果安装的是32位的python,报错python DatabaseError: DPI-1047: 32-bit Oracle Client library cannot be loade,则需要用32位的instantclient_11_2里面的oci.dll、oraocci11.dll、oraociei11.dll的动态库放进python安装目录的Lib\site-packages下

 

 

 

 

你可能感兴趣的:(Oracle,python)