I'm really new to python, it's the first time I'm writing it actually. And I'm creating a program that gets the number of views on a Twitch.tv stream, but I'm getting an error Expected string or buffer Python when I'm calling this function
def getURL():
output = subprocess.Popen(["livestreamer", "twitch.tv/streamname", "-j"], stdout=subprocess.PIPE).communicate()[1]
return json.loads(output)["streams"]["worst"]["url"]
I'm calling the function from here:
urls = []
urls.append(getURL())
What am I doing wrong? I've been trying to figure this one out for ages... And if anybody knows how to fix this, I'd be the happiest man alive ;)
Thanks in advance.
EDIT:
This is all the code I have.
import requests
import subprocess
import json
import sys
import threading
import time
urls = []
urlsUsed = []
def getURL():
output = subprocess.Popen(["livestreamer", "twitch.tv/hemzk", "-j"], stdout=subprocess.PIPE).communicate()[1]
return json.loads(output)["streams"]["worst"]["url"]
def build():
global numberOfViewers
urls.append(getURL())
And I'm getting the error at return json.loads(output)["streams"]["worst"]["url"]