i was trying to use a code writing in python 2.7 with python 3.5,but i coudn't solve this error
TypeError: the JSON object must be str, not 'bytes'
while has_next_page:
after = '' if after is '' else "&after={}".format(after)
base_url = base + node + parameters + after + since + until
url = getFacebookPageFeedUrl(base_url)
statuses = json.loads(request_until_succeed(url))
reactions = getReactionsForStatuses(base_url)
reactions = getReactionsForStatuses(base_url)
for status in statuses['data']:
# Ensure it is a status with the expected metadata
if 'reactions' in status:
status_data = processFacebookPageFeedStatus(status)
reactions_data = reactions[status_data[0]]
# calculate thankful/pride through algebra
num_special = status_data[6] - sum(reactions_data)
w.writerow(status_data + reactions_data + (num_special,))
num_processed += 1
if num_processed % 100 == 0:
print(("{} Statuses Processed: {}".format
(num_processed, datetime.datetime.now())))
# if there is no next page, we're done.
if 'paging' in statuses:
after = statuses['paging']['cursors']['after']
else:
has_next_page = False
the probleme is 6th line with json.load, is any one who have idea how to solve it ? thank you
here is the request_until_succeed function:
def request_until_succeed(url):
req = Request(url)
success = False
while success is False:
try:
response = urlopen(req)
if response.getcode() == 200:
success = True
except Exception as e:
print(e)
time.sleep(5)
print("Error for URL {}: {}".format(url, datetime.datetime.now()))
print("Retrying.")
return response.read()