3 Replies - 1985 Views - Last Post: 10 July 2011 - 02:28 PM Rate Topic: -----

#1 xheartonfire43x  Icon User is offline

  • D.I.C Regular

Reputation: 46
  • View blog
  • Posts: 454
  • Joined: 22-December 08

Yaml file throwing errors

Posted 10 July 2011 - 12:58 PM

I am a super beginner with Ruby, so please give me any pointers if you have them.

I am working on a Twitter application to work with and Arduino board. All the application does is monitor a twitter account and check for new messages every 15 seconds. I had everything working until I decided that I want to post the code to GitHub. I moved all of my private configuration things (Application keys and user keys) into a Yaml file setup like the following:

app:
	oauth_consumer_token: consumertokenkey
	oauth_consumer_secret: consumersecretkey
user:
	key: userkey
	secret: usersecret


Then to parse the file I used the following code as I found on some blogs:

require 'yaml'

CONFIG = YAML::load_file("conf.yml")


Now when I run the code I get an error message:

/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/yaml.rb:133:in `load': syntax error on line 1, col 22: `	oauth_consumer_token: consumertokenkey' (ArgumentError)
	from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/yaml.rb:133:in `load'
	from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/yaml.rb:144:in `load_file'
	from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/yaml.rb:143:in `open'
	from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/yaml.rb:143:in `load_file'
	from twituino.rb:6


I can't seem to figure out what the actually syntax error is though after searching online for anything that might help.

Is This A Good Question/Topic? 0
  • +

Replies To: Yaml file throwing errors

#2 sepp2k  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2153
  • View blog
  • Posts: 3,315
  • Joined: 21-June 11

Re: Yaml file throwing errors

Posted 10 July 2011 - 02:13 PM

You have tabs in your yaml file, which is not allowed. Replace them with spaces and it will work.
Was This Post Helpful? 0
  • +
  • -

#3 xheartonfire43x  Icon User is offline

  • D.I.C Regular

Reputation: 46
  • View blog
  • Posts: 454
  • Joined: 22-December 08

Re: Yaml file throwing errors

Posted 10 July 2011 - 02:21 PM

Thanks that worked. Kind of annoying that yaml doesn't allow tabs though. Is there a reason that it won't allow tabs?
Was This Post Helpful? 0
  • +
  • -

#4 sepp2k  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2153
  • View blog
  • Posts: 3,315
  • Joined: 21-June 11

Re: Yaml file throwing errors

Posted 10 July 2011 - 02:28 PM

In languages with significant indentation it can be problematic to mix tabs and spaces. I assume that the YAML designers figured that the simplest and/or cleanest way to avoid such problems would be to simply disallow tabs altogether.

Edit:

This FAQ says the following:

Quote

Tabs have been outlawed since they are treated differently by different editors and tools. And since indentation is so critical to proper interpretation of YAML, this issue is just too tricky to even attempt. Indeed Guido van Rossum of Python has acknowledged that allowing TABs in Python source is a headache for many people and that were he to design Python again, he would forbid them.

This post has been edited by sepp2k: 10 July 2011 - 02:32 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1