1 | NO CONTENT: modified file, binary diff hidden |
|
NO CONTENT: modified file, binary diff hidden |
@@ -14,6 +14,11 import json | |||||
14 | #import pathlib |
|
14 | #import pathlib | |
15 | import uuid |
|
15 | import uuid | |
16 |
|
16 | |||
|
17 | if sys.version_info.major == 3: | |||
|
18 | from urllib.parse import urlparse | |||
|
19 | else: | |||
|
20 | import urlparse | |||
|
21 | ||||
17 | class JROAPI(): |
|
22 | class JROAPI(): | |
18 | """ |
|
23 | """ | |
19 | FINALIDAD: |
|
24 | FINALIDAD: | |
@@ -61,10 +66,19 class JROAPI(): | |||||
61 | 4) ¿Cual era el resultado que usted esperaba? |
|
66 | 4) ¿Cual era el resultado que usted esperaba? | |
62 | """ |
|
67 | """ | |
63 | def __init__(self, url, Authorization=None): |
|
68 | def __init__(self, url, Authorization=None): | |
64 | ua = 'CKAN_JRO/1.1 (+'+str(url)+')' |
|
69 | #-------- Insecure -------# | |
|
70 | self.verify = None | |||
|
71 | session = None | |||
|
72 | if urlparse(url).scheme == 'https': | |||
|
73 | session = requests.Session() | |||
|
74 | session.verify = False | |||
|
75 | self.verify = False | |||
|
76 | #--------------------------# | |||
|
77 | self.url = url | |||
|
78 | ua = 'CKAN_JRO/2.9.2 (+'+str(self.url)+')' | |||
65 | #ua = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36' |
|
79 | #ua = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36' | |
66 | self.ckan = RemoteCKAN(url, apikey=Authorization, user_agent=ua) |
|
80 | self.ckan = RemoteCKAN(self.url, apikey=Authorization, user_agent=ua, session=session) | |
67 | #self.ckan = RemoteCKAN(url, apikey=Authorization) |
|
81 | #self.ckan = RemoteCKAN(self.url, apikey=Authorization) | |
68 | self.Authorization = Authorization |
|
82 | self.Authorization = Authorization | |
69 | # Change for --> self.separator = os.sep |
|
83 | # Change for --> self.separator = os.sep | |
70 | if platform.system() == 'Windows': |
|
84 | if platform.system() == 'Windows': | |
@@ -785,7 +799,12 class JROAPI(): | |||||
785 |
|
799 | |||
786 | def download_by_step(self, response, tempdir_name): |
|
800 | def download_by_step(self, response, tempdir_name): | |
787 | try: |
|
801 | try: | |
788 | with requests.get(response['url'], stream=True, headers={'Authorization': self.Authorization}) as resp: |
|
802 | # ---------- REPLACE URL --------- # | |
|
803 | if urlparse(self.url).netloc != 'www.igp.gob.pe' and urlparse(response['url']).netloc == 'www.igp.gob.pe': | |||
|
804 | response['url'] = response['url'].replace(urlparse(response['url']).scheme + '://' + urlparse(response['url']).netloc, | |||
|
805 | urlparse(self.url).scheme + '://' + urlparse(self.url).netloc) | |||
|
806 | #----------------------------------# | |||
|
807 | with requests.get(response['url'], stream=True, headers={'Authorization': self.Authorization}, verify=self.verify) as resp: | |||
789 | if resp.status_code == 200: |
|
808 | if resp.status_code == 200: | |
790 | with open(tempdir_name+response['name'], 'wb') as file: |
|
809 | with open(tempdir_name+response['name'], 'wb') as file: | |
791 | for chunk in resp.iter_content(chunk_size = self.chunk_size): |
|
810 | for chunk in resp.iter_content(chunk_size = self.chunk_size): |
General Comments 0
You need to be logged in to leave comments.
Login now