octohub / GroupMeAnalytics

A simple Python app that gives insight into your GroupMe conversations.
MIT License
15 stars 23 forks source link

No JSON object could be decoded #2

Closed kdgeck512 closed 5 years ago

kdgeck512 commented 8 years ago

Hey -

Trying to put this together for my groupme thread. I run the app in PyCharm, using Python 2.7, and after I enter my developer access token, I'm getting the below error. I'm not really a programmer so I'm likely making an obvious error, so if you don't mind pointing out what might be wrong, that'd be super helpful. Thanks. Kevin.

Traceback (most recent call last): File "/Users/Kevin/Downloads/GroupMeAnalytics-master/groupme_analytics.py", line 247, in menu() File "/Users/Kevin/Downloads/GroupMeAnalytics-master/groupme_analytics.py", line 17, in menu groups_data = print_all_groups_with_number_beside_each() File "/Users/Kevin/Downloads/GroupMeAnalytics-master/groupme_analytics.py", line 28, in print_all_groups_with_number_beside_each data = response.json() File "/Users/Kevin/Downloads/GroupMeAnalytics-master/requests/models.py", line 805, in json return complexjson.loads(self.text, kwargs) File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/init**.py", line 339, in loads return _default_decoder.decode(s) File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/decoder.py", line 364, in decode obj, end = self.raw_decode(s, idx=_w(s, 0).end()) File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/decoder.py", line 382, in raw_decode raise ValueError("No JSON object could be decoded") ValueError: No JSON object could be decoded

derektucker commented 8 years ago

I'm having the same problem. Also not an experienced developer so might be making an obvious mistake.

jwill0213 commented 8 years ago

I believe I have fixed this issue. In the function print_all_groups_with_number_beside_each() the url has an extra '/' between groups and ?token. Remove this and it should work as intended. so replace this response = requests.get("https://api.groupme.com/v3/groups/?token="+at) to response = requests.get("https://api.groupme.com/v3/groups?token="+at) Hope this helps.

cdonohue413 commented 8 years ago

Hey there- I came across this looking for a good analytics package for my groupme with friends and this looks awesome!! I am having trouble getting it to run though. I have done what jwill0213 has said to change in the last comment, but now getting an error reading: Can someone help?

Traceback (most recent call last): File "groupme_analytics.py", line 245, in menu() File "groupme_analytics.py", line 15, in menu groups_data = print_all_groups_with_number_beside_each() File "groupme_analytics.py", line 28, in print_all_groups_with_number_beside_each if len(data['response']) == 0: TypeError: object of type 'NoneType' has no len()

jwill0213 commented 8 years ago

@cdonohue413 How far in the program do you get before this error happens? Does it happen right when you start it? It looks like to me that whatever response you are trying to get from the server is empty. I'd say make sure your api token is entered correctly and the link is correct. Try going to your web browser at the "https://api.groupme.com/v3/groups?token=" and add your token at the end. You should get a lot of text beginning with {"response":[Lots of text and info following] . If not there is something wrong with your token. Let me know if you still can't get it to work and I'll do my best to help

cdonohue413 commented 8 years ago

Hey there! Thanks so much for replying, I really appreciate it!!! So this has been interesting. I can get this script to run just fine for all of my other groupme groups, but not this main one that I am trying to use it for. It's getting to about 55% complete, then throws the error that I sent in original message. Not sure why only on this group--any ideas? I am a beginner with a lot of this stuff so I don't really know where to go or how to fix from here, so anything is appreciated!

Sent from my iPhone

On Mar 3, 2016, at 5:17 PM, Jordan Williams notifications@github.com wrote:

@cdonohue413 How far in the program do you get before this error happens? Does it happen right when you start it? It looks like to me that whatever response you are trying to get from the server is empty. I'd say make sure your api token is entered correctly and the link is correct. Try going to your web browser at the "https://api.groupme.com/v3/groups?token=" and add your token at the end. You should get a lot of text beginning with {"response":[Lots of text and info following] . If not there is something wrong with your token. Let me know if you still can't get it to work and I'll do my best to help

— Reply to this email directly or view it on GitHub.

jwill0213 commented 8 years ago

Hmm that is strange. According to the first error messages you posted the error happens in the function print_all_groups_with_number_beside_each() however that should only be called at the beginning to make the list of groups so if it starts running and fails half way through then I'm not sure why that function is running at that point. Another thing I'm not sure of is why len(data['response']) is returning a 'NoneType'. At the beginning how many messages does it say its reading? And is the error the same every time with that group?

cdonohue413 commented 8 years ago

Really weird- but I ran it like 30 minutes ago and it worked!!

I really appreciate you helping and taking the time to look into it!

Sent from my iPhone

On Mar 4, 2016, at 1:32 PM, Jordan Williams notifications@github.com wrote:

Hmm that is strange. According to the first error messages you posted the error happens in the function print_all_groups_with_number_beside_each() however that should only be called at the beginning to make the list of groups so if it starts running and fails half way through then I'm not sure why that function is running at that point. Another thing I'm not sure of is why len(data['response']) is returning a 'NoneType'. At the beginning how many messages does it say its reading? And is the error the same every time with that group?

— Reply to this email directly or view it on GitHub.

jwill0213 commented 8 years ago

No problem. Glad I could help some. I'm still learning python and going through code always help learn it.

soumia03 commented 7 years ago

hi i work for sentiment analysis from twitter multiligual so i need to collect tweet containing emoticon i tried this code but it give me error: import oauth2 as oauth import urllib2 as urllib import json import string

access_token_key = "800411290640400384-eP4QgdY4ennfKIbYA0DF7UH590E0eva" access_token_secret = "DSZgGwkWaEyBjhaBAMXHJ8tYNhiMbKYMxjMepOdOUCF93"

consumer_key = "01wPP3wKPP3nzP9jpimdAamPq" consumer_secret = "SxXlNHuab3nu2GHHM41sfl9UxxJfUfoNfKWXdAWkQETVn1tk4H"

_debug = 0

oauth_token = oauth.Token(key=access_token_key, secret=access_token_secret) oauth_consumer = oauth.Consumer(key=consumer_key, secret=consumer_secret)

signature_method_hmac_sha1 = oauth.SignatureMethod_HMAC_SHA1()

http_method = "GET"

http_handler = urllib.HTTPHandler(debuglevel=_debug) https_handler = urllib.HTTPSHandler(debuglevel=_debug)

''' Construct, sign, and open a twitter request using the hard-coded credentials above. '''

def twitterreq(url, method, parameters): req = oauth.Request.from_consumer_and_token(oauth_consumer, token=oauth_token, http_method=http_method, http_url=url, parameters=parameters)

req.sign_request(signature_method_hmac_sha1, oauth_consumer, oauth_token)

headers = req.to_header()

if http_method == "POST":
    encoded_post_data = req.to_postdata()
else:
    encoded_post_data = None
    url = req.to_url()

opener = urllib.OpenerDirector()
opener.add_handler(http_handler)
opener.add_handler(https_handler)

response = opener.open(url, encoded_post_data)

return response

def hasEmoticon(text): emoticonlist = [':-)', ':)', '=)', ':-D', ':D', '8-D', '8D', 'x-D', 'xD', 'X-D', 'XD', ':-(', ':(', ':-|', ':|', ":'-(", ":'()", ":'-)", ":')", ':-o', ':-O', ':o', ':O', 'o_O', 'o_0', 'o.O', ':*', ';-)', ';)', '%-)', '%)', '<3', '</3']

for e in emoticonlist:
    if text.find(e) > -1:
        return True
return False

def fetchsamples(): tweetfile = open('tweetswithemoticons.txt', 'a')

url = "https://stream.twitter.com/1/statuses/sample.json"
parameters = []
response = twitterreq(url, "GET", parameters)
ctr = 0
for line in response:
    # extract tweet text from line

     jtweet = json.loads(line)
    # print line

        #continue

     if "text" in jtweet and "lang" in jtweet and jtweet["lang"] == 'en':
        tweet = (jtweet["text"]).encode('utf-8'), "\n"
        tweet = ' '.join(tweet)
        if hasEmoticon(tweet):
            # print tweet
            tweet = tweet.replace("\n",
                                  " ")  # basically, so that one line in file correponds to exactly one full tweet
            tweetfile.write("\n" + tweet)
            ctr += 1
            if ctr % 100 == 0:
                print ctr

tweetfile.close()

if name == 'main': fetchsamples() l'error: jtweet = json.loads(line) File "C:\Python27\lib\json__init__.py", line 339, in loads return _default_decoder.decode(s) File "C:\Python27\lib\json\decoder.py", line 364, in decode obj, end = self.raw_decode(s, idx=_w(s, 0).end()) File "C:\Python27\lib\json\decoder.py", line 382, in raw_decode raise ValueError("No JSON object could be decoded") ValueError: No JSON object could be decoded so please help me

czue commented 7 years ago

as others have mentioned - this is fixed by https://github.com/octohub/GroupMeAnalytics/pull/5 which should be merged.

ErikBoesen commented 5 years ago

This is fixed by #5, which has just been merged!