0

i have a problem running my script in linux using python 2.6, i get an error:

/usr/lib/python2.6/site-packages/requests-2.18.4-py2.6.egg/requests/init.py:80: RequestsDependencyWarning: urllib3 (1.22) or chardet (2.2.1) doesn't match a supported version! RequestsDependencyWarning) Traceback (most recent call last): File "mapping_prepaid.py", line 3, in from requests import post,Session File "/usr/lib/python2.6/site-packages/requests-2.18.4-py2.6.egg/requests/init.py", line 97, in from . import utils File "/usr/lib/python2.6/site-packages/requests-2.18.4-py2.6.egg/requests/utils.py", line 24, in from . import certs File "/usr/lib/python2.6/site-packages/requests-2.18.4-py2.6.egg/requests/certs.py", line 15, in from certifi import where

my code (running using python 2.6 on linux):

from _future_ import print_function
from contextlib import closing
from requests import post,Session
#from multiprocessing import Pool
from multiprocessing.dummy import Pool 
from datetime import datetime as dt
from time import time
from csv import DictReader
import sys

BASE_URL = 'https://xx.xxx.xxx.xx:443/siebel/v1.0/service/project/'
headers = {'Content-Type': 'application/json','Authorization': 'Basic Qkxxxxxxx='}

#run a file from command line
list_dict = []
filename = sys.argv[1]
with open(filename, 'r') as g:
    f_reader = DictReader(g, delimiter='|',
                fieldnames=['transactionId','channel','userId','intRef','serviceId','projectId'])
    for d in f_reader:
        list_dict.append(dict(d))

def resource_post(data_from_json):
    timestamp = dt.now().strftime('%Y%m%d %H:%M:%S:%f')[:-3]  # timestamp
    data_from_json["timestamp"] = timestamp
    post_data = {
        "body": data_from_json,
    }
    response = post(BASE_URL, headers=headers, json=post_data)
    response.raise_for_status()
    return response.json()

def main():
    start = time()
    with open("output.txt", "a") as outf:
        pool = Pool()
        with closing(pool) as p: #ubah
            for resp in p.imap_unordered(resource_post, list_dict):
                print(resp)
                print(resp["responseCode"], resp["ResponseMessage"], resp["transactionId"], sep="|", file=outf)
    elapsed = (time() - start)
    print("\n", "time elapsed is :", elapsed)
    with open("complete.txt", "a") as outf:
        print(filename,"completed",file=outf)

if _name_ == '_main_':
    main()

please help me to solve this problem. error in my library and my headers.

Irfan
  • 61
  • 5

1 Answers1

0

I recommend you to use Python3 because most libraries doesn't support Python2 these days. It says you didn't downloaded certifi. pip install certifi I don't know much about this "certifi" library. But it is installed with pip automatically on my Mac.

electromeow
  • 211
  • 2
  • 8