Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Twitter::Error: 757: unexpected token at '' #547

Closed
jtippett opened this issue Mar 25, 2014 · 10 comments
Closed

Twitter::Error: 757: unexpected token at '' #547

jtippett opened this issue Mar 25, 2014 · 10 comments

Comments

@jtippett
Copy link

I've recently upgraded to rails 4 and twitter 5.8.0 and am seeing strange parsing errors:

2.1.1 :038 > client.status "test"
Twitter::Error: 757: unexpected token at ''
  from /home/deploy/rails-apps/my_app/shared/bundle/ruby/2.1.0/gems/twitter-5.8.0/lib/twitter/rest/client.rb:96:in `rescue in request'
  from /home/deploy/rails-apps/my_app/shared/bundle/ruby/2.1.0/gems/twitter-5.8.0/lib/twitter/rest/client.rb:92:in `request'
  from /home/deploy/rails-apps/my_app/shared/bundle/ruby/2.1.0/gems/twitter-5.8.0/lib/twitter/rest/client.rb:63:in `get'
  from /home/deploy/rails-apps/my_app/shared/bundle/ruby/2.1.0/gems/twitter-5.8.0/lib/twitter/request.rb:22:in `perform'
  from /home/deploy/rails-apps/my_app/shared/bundle/ruby/2.1.0/gems/twitter-5.8.0/lib/twitter/request.rb:29:in `perform_with_object'
  from /home/deploy/rails-apps/my_app/shared/bundle/ruby/2.1.0/gems/twitter-5.8.0/lib/twitter/rest/utils.rb:39:in `perform_with_object'
  from /home/deploy/rails-apps/my_app/shared/bundle/ruby/2.1.0/gems/twitter-5.8.0/lib/twitter/rest/tweets.rb:60:in `status'
  from (irb):38
  from /home/deploy/rails-apps/my_app/shared/bundle/ruby/2.1.0/gems/railties-4.0.4/lib/rails/commands/console.rb:90:in `start'
  from /home/deploy/rails-apps/my_app/shared/bundle/ruby/2.1.0/gems/railties-4.0.4/lib/rails/commands/console.rb:9:in `start'
  from /home/deploy/rails-apps/my_app/shared/bundle/ruby/2.1.0/gems/railties-4.0.4/lib/rails/commands.rb:62:in `<top (required)>'

I'm not sure what could be causing this; as you can see it's a plain string with nothing weird. Is this a known issue?

@sferik
Copy link
Owner

sferik commented Mar 25, 2014

Try

client.update "test"

@sferik sferik closed this as completed Mar 25, 2014
@jtippett
Copy link
Author

Sure, actually I had tried that as well.

2.1.1 :004 > client.update 'test'
Twitter::Error: 757: unexpected token at ''
  from /home/deploy/rails-apps/my_app/shared/bundle/ruby/2.1.0/gems/twitter-5.8.0/lib/twitter/rest/client.rb:96:in `rescue in request'
  from /home/deploy/rails-apps/my_app/shared/bundle/ruby/2.1.0/gems/twitter-5.8.0/lib/twitter/rest/client.rb:92:in `request'
  from /home/deploy/rails-apps/my_app/shared/bundle/ruby/2.1.0/gems/twitter-5.8.0/lib/twitter/rest/client.rb:69:in `post'
  from /home/deploy/rails-apps/my_app/shared/bundle/ruby/2.1.0/gems/twitter-5.8.0/lib/twitter/request.rb:22:in `perform'
  from /home/deploy/rails-apps/my_app/shared/bundle/ruby/2.1.0/gems/twitter-5.8.0/lib/twitter/request.rb:29:in `perform_with_object'
  from /home/deploy/rails-apps/my_app/shared/bundle/ruby/2.1.0/gems/twitter-5.8.0/lib/twitter/rest/utils.rb:39:in `perform_with_object'
  from /home/deploy/rails-apps/my_app/shared/bundle/ruby/2.1.0/gems/twitter-5.8.0/lib/twitter/rest/tweets.rb:148:in `update!'
  from /home/deploy/rails-apps/my_app/shared/bundle/ruby/2.1.0/gems/twitter-5.8.0/lib/twitter/rest/tweets.rb:120:in `update'
  from (irb):4
  from /home/deploy/rails-apps/my_app/shared/bundle/ruby/2.1.0/gems/railties-4.0.4/lib/rails/commands/console.rb:90:in `start'
  from /home/deploy/rails-apps/my_app/shared/bundle/ruby/2.1.0/gems/railties-4.0.4/lib/rails/commands/console.rb:9:in `start'
  from /home/deploy/rails-apps/my_app/shared/bundle/ruby/2.1.0/gems/railties-4.0.4/lib/rails/commands.rb:62:in `<top (required)>'

It happens no matter what I do:

2.1.1 :009 > client.user('gem')
Twitter::Error: 757: unexpected token at ''
  from /home/deploy/rails-apps/my_app/shared/bundle/ruby/2.1.0/gems/twitter-5.8.0/lib/twitter/rest/client.rb:96:in `rescue in request'
  from /home/deploy/rails-apps/my_app/shared/bundle/ruby/2.1.0/gems/twitter-5.8.0/lib/twitter/rest/client.rb:92:in `request'
  from /home/deploy/rails-apps/my_app/shared/bundle/ruby/2.1.0/gems/twitter-5.8.0/lib/twitter/rest/client.rb:63:in `get'
  from /home/deploy/rails-apps/my_app/shared/bundle/ruby/2.1.0/gems/twitter-5.8.0/lib/twitter/request.rb:22:in `perform'
  from /home/deploy/rails-apps/my_app/shared/bundle/ruby/2.1.0/gems/twitter-5.8.0/lib/twitter/request.rb:29:in `perform_with_object'
  from /home/deploy/rails-apps/my_app/shared/bundle/ruby/2.1.0/gems/twitter-5.8.0/lib/twitter/rest/utils.rb:39:in `perform_with_object'
  from /home/deploy/rails-apps/my_app/shared/bundle/ruby/2.1.0/gems/twitter-5.8.0/lib/twitter/rest/users.rb:257:in `user'
  from (irb):9
  from /home/deploy/rails-apps/my_app/shared/bundle/ruby/2.1.0/gems/railties-4.0.4/lib/rails/commands/console.rb:90:in `start'
  from /home/deploy/rails-apps/my_app/shared/bundle/ruby/2.1.0/gems/railties-4.0.4/lib/rails/commands/console.rb:9:in `start'
  from /home/deploy/rails-apps/my_app/shared/bundle/ruby/2.1.0/gems/railties-4.0.4/lib/rails/commands.rb:62:in `<top (required)>'
  from bin/rails:10:in `require'
  from bin/rails:10:in `<main>'

@sferik
Copy link
Owner

sferik commented Mar 25, 2014

It looks like the Twitter API is returning invalid JSON. Can you try making the same request with twurl using the same credentials?

@jtippett
Copy link
Author

I had to set up a different account, but I'm not seeing any different results.

$ twurl -d 'status=Testing twurl' /1.1/statuses/update.json
{"created_at":"Wed Mar 26 00:51:30 +0000 2014","id":448623243679657984,"id_str":"448623243679657984","text":"Testing twurl","source":"\u003ca href=\"http:\/\/www.google.com\/\" rel=\"nofollow\"\u003eda G Shou\u003c\/a\u003e","truncated":false,"in_reply_to_status_id":null,"in_reply_to_status_id_str":null,"in_reply_to_user_id":null,"in_reply_to_user_id_str":null,"in_reply_to_screen_name":null,"user":{"id":2411695698,"id_str":"2411695698","name":"Dev Test","screen_name":"airtester123","location":"","description":"","url":null,"entities":{"description":{"urls":[]}},"protected":false,"followers_count":0,"friends_count":0,"listed_count":0,"created_at":"Tue Mar 25 23:40:33 +0000 2014","favourites_count":0,"utc_offset":null,"time_zone":null,"geo_enabled":false,"verified":false,"statuses_count":1,"lang":"en","contributors_enabled":false,"is_translator":false,"is_translation_enabled":false,"profile_background_color":"C0DEED","profile_background_image_url":"http:\/\/abs.twimg.com\/images\/themes\/theme1\/bg.png","profile_background_image_url_https":"https:\/\/abs.twimg.com\/images\/themes\/theme1\/bg.png","profile_background_tile":false,"profile_image_url":"http:\/\/abs.twimg.com\/sticky\/default_profile_images\/default_profile_6_normal.png","profile_image_url_https":"https:\/\/abs.twimg.com\/sticky\/default_profile_images\/default_profile_6_normal.png","profile_link_color":"0084B4","profile_sidebar_border_color":"C0DEED","profile_sidebar_fill_color":"DDEEF6","profile_text_color":"333333","profile_use_background_image":true,"default_profile":true,"default_profile_image":true,"following":false,"follow_request_sent":false,"notifications":false},"geo":null,"coordinates":null,"place":null,"contributors":null,"retweet_count":0,"favorite_count":0,"entities":{"hashtags":[],"symbols":[],"urls":[],"user_mentions":[]},"favorited":false,"retweeted":false,"lang":"sv"}

vs

[4] pry(main)> client.update "test"
Twitter::Error: 757: unexpected token at ''
from /Users/james/.rvm/gems/ruby-2.1.1@airtester/gems/twitter-5.8.0/lib/twitter/rest/client.rb:96:in `rescue in request'

I then dumped the output from twurl into a file and attempted to parse it in ruby, which worked fine.

At a bit of a loss. Any ideas?

@sferik
Copy link
Owner

sferik commented Mar 26, 2014

No, that’s quite odd. Can you try running the same script on a different computer?

@jtippett
Copy link
Author

Yeah, it fails in multiple environments, including linux servers.

I'm going on the assumption it's a library we have causing the issue; will investigate further.

@kennym
Copy link

kennym commented Apr 3, 2014

I am getting the same error! #548

@kennym
Copy link

kennym commented Apr 3, 2014

I think this has something do with this issue #473 - the author suggests that the response is GZipped... checking into that

@kennym
Copy link

kennym commented Apr 3, 2014

YES! The response is zipped... writing a pull request now

@jtippett
Copy link
Author

Yeah, as the other issue said, the issue was right-http, which I have now terminated with extreme prejudiced. Thanks for the help!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants