Skip to content

Commit 02c759f

Browse files
committed
Added try/catch and if statements to imports to fix compilation errors
1 parent adde0ab commit 02c759f

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

InstagramAPI.py

+13-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#!/usr/bin/env python
22
# -*- coding: utf-8 -*-
3+
34
import requests
45
import random
56
import json
@@ -10,6 +11,12 @@
1011
import time
1112
import copy
1213
import math
14+
import sys
15+
16+
#For Python 3.x, urllib is split so we must import another library
17+
if sys.version_info.major == 3:
18+
import urllib.parse
19+
1320
from ImageUtils import getImageSize
1421
from requests_toolbelt import MultipartEncoder
1522
from moviepy.editor import VideoFileClip
@@ -558,7 +565,12 @@ def getLikedMedia(self,maxid=''):
558565
return self.SendRequest('feed/liked/?max_id='+str(maxid))
559566

560567
def generateSignature(self, data):
561-
return 'ig_sig_key_version=' + self.SIG_KEY_VERSION + '&signed_body=' + hmac.new(self.IG_SIG_KEY.encode('utf-8'), data.encode('utf-8'), hashlib.sha256).hexdigest() + '.' + urllib.parse.quote(data)
568+
try:
569+
parsedData = urllib.parse.quote(data)
570+
except AttributeError:
571+
parsedData = urllib.quote(data)
572+
573+
return 'ig_sig_key_version=' + self.SIG_KEY_VERSION + '&signed_body=' + hmac.new(self.IG_SIG_KEY.encode('utf-8'), data.encode('utf-8'), hashlib.sha256).hexdigest() + '.' + parsedData
562574

563575
def generateDeviceId(self, seed):
564576
volatile_seed = "12345"

0 commit comments

Comments
 (0)