通过api 获取eloqua的数据(完整版)

在服务器上运行Python3代码频繁请求Eloqua数据时,遇到[Errno 104] Connection reset by peer错误。为解决此问题,可以采用循环机制,当发生重定向时重新尝试请求,限定最多尝试10次。该问题在Windows系统中未出现。
摘要由CSDN通过智能技术生成

有一个注意点,就是代码放在服务器上时,会出现频繁请求数据时,eloqua会重定向url([Errno 104] Connection reset by peer)),这里处理的方法是,添加循环,重新请求,当然请求的次数限制在10次内,如果十次都没有通过,则停止请求(在windows系统上没发现这个问题)

import json
    import base64
    import requests
    import datetime
    import time
    import psycopg2
    import os
    import configparser

# 用来操作数据库的类
class GPCommand(object):
    # 类的初始化
    def __init__(self):
      self.hostname = 'xxxxxx'
      self.username = 'xxxxxx'
      self.password = 'xxxxxxxxxx'
      self.database = 'xxxxx'
    def connectGp(self):
      try:
        #链接数据库
        #读取配置利用connect链接数据库
        self.connect = psycopg2.connect( host=self.hostname, user=self.username, password=self.password, dbname=self.database )
        #创建一个新的cursor
        self.cursor = self.connect.cursor()
        print("connect gp successful.")
        return ('con_successful')
      except psycopg2.Error:
          error = 'Failed to setup Postgres environment.\n{0}'.format(sys.exc_info())
          print('connect gp error.'+'\n')
          return 'con_error'+ error
#关闭数据库
    def closeMysql(self):
        self.cursor.close()
        self.connect.close()
        print("database closed")

    def insert_data(self,table_name,dict):
        try:
          dicts_values = []
          # print(dict)
          dict_key = list(dict.keys())
          table_key = ",".join(dict_key)
          ROWstr = ''  # 行字段
          for key in dict.keys(
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值