我尝试使用Ruby SMS Fu gem从我的电子邮件地址向某人发送自动短信。另外,我没有使用Rails;这是一个简单的Ruby脚本,它从某个站点获取某些信息,然后根据所述信息向某人发送消息。不幸的是,当我尝试在我的脚本中使用SMS Fu时,我遇到了一个非常奇怪的错误:
/Users/my_username/.rvm/rubies/ruby-2.4.0/lib/ruby/2.4.0/psych.rb:377:in `parse': (<unknown>): found character that cannot start any token while scanning for the next token at line 7 column 12 (Psych::SyntaxError)
from /Users/my_username/.rvm/rubies/ruby-2.4.0/lib/ruby/2.4.0/psych.rb:377:in `parse_stream'
from /Users/my_username/.rvm/rubies/ruby-2.4.0/lib/ruby/2.4.0/psych.rb:325:in `parse'
from /Users/my_username/.rvm/rubies/ruby-2.4.0/lib/ruby/2.4.0/psych.rb:252:in `load'
from /Users/my_username/.rvm/gems/ruby-2.4.0/gems/sms_fu-1.1.2/lib/sms_fu/sms_fu.rb:55:in `config_yaml'
from /Users/my_username/.rvm/gems/ruby-2.4.0/gems/sms_fu-1.1.2/lib/sms_fu/sms_fu.rb:61:in `carriers'
from /Users/my_username/.rvm/gems/ruby-2.4.0/gems/sms_fu-1.1.2/lib/sms_fu/sms_fu.rb:77:in `carrier'
from /Users/my_username/.rvm/gems/ruby-2.4.0/gems/sms_fu-1.1.2/lib/sms_fu/sms_fu.rb:73:in `carrier_email'
from /Users/my_username/.rvm/gems/ruby-2.4.0/gems/sms_fu-1.1.2/lib/sms_fu/sms_fu.rb:85:in `sms_address'
from /Users/my_username/.rvm/gems/ruby-2.4.0/gems/sms_fu-1.1.2/lib/sms_fu/sms_fu.rb:43:in `deliver'
from ./my_script.rb:69:in `<main>'
我的脚本中的内容如下所示:
#!/usr/bin/env ruby
require "active_support" # action_mailer, one of sms_fu's dependencies, throws
# an error without this
require "sms_fu"
# gather information from our site...
# Pony delivery via SMTP
PONY_CONFIG = {
:via => :smtp,
:via_options => {
:address => "smtp.gmail.com",
:port => "587",
:user_name => "me@example.com",
:password => "pass",
:authentication => :plain,
:enable_starttls_auto => true,
:domain => "localhost.localdomain"
}}
sms_fu = SMSFu::Client.configure(:delivery => :pony, :pony_config => PONY_CONFIG)
sms_fu.deliver("123456789", "some carrier", "my message", from: "me@example") # this line triggers the error
奇怪的是这个错误是抱怨解析YAML,但根据SMS Fu的README文件,如果我使用Rails,我只需要担心设置YAML文件,我和#39;我没有。但是,在查看SMS Fu的来源时,似乎硬编码使用SMSFu.config_yaml
方法中的YAML文件,该方法随后间接或直接由SMS Fu中的其他方法使用,一直回到SMSFu::Client#deliver
,这是导致错误的那个。
所以,我想我的问题是:如何才能让这个错误停止发生,以便我可以在没有YAML麻烦的情况下发送我的短信?
编辑:
忘了提供一些版本/环境信息:我在OS X 10.12.2上运行这个脚本,并且我使用Ruby 2.4.0(虽然这个Ruby版本在上面的错误中显示)。