bstascavage / plexReport

Scripts to generate a weekly email of new additions to Plex
67 stars 17 forks source link

No Email sending, error and config attached #45

Closed jamespardon closed 9 years ago

jamespardon commented 9 years ago

As per the forum. I'm trying to run this on OSX Yosemite. Running I get the following when run -

Quantum:bin pardonator$ ruby plexReport.rb /Users/pardonator/Documents/PlexReport/plexReport/bin/mailReport.rb:54:in sendMail': undefined methodeach' for nil:NilClass (NoMethodError) from plexReport.rb:346:in main' from plexReport.rb:350:in

'

jamespardon commented 9 years ago

Config :


email: title: ‘Plex New Stuff’ plex: server: 192.168.1.90 api_key: tcfjqQzU7qy4sqGkQ1Yq mail: address: smtp.gmail.com port: 587 username: myemail@gmail.com password: mypassword from: myemail@gmail.com subject: 'New' recipients_email: [‘email1’, ‘email2’] recipients: ['Test']

ersw1187 commented 9 years ago

As far as I can see your config film looks just like the one I have on OS X

If I look the file mailreport.rb is see that lines 51-57 read as follows: if !$testEmail if $plexEmails plex_users = plexTv.get('/pms/friends/all') plex_users['MediaContainer']['User'].each do | user | users.push(user['email']) end end

The error occurs in the piece of code "plex_users['MediaContainer']['User'].each do | user |"

Have you tried to run it with the -t option. This will only generate an e-mail to your own e-mail address. If this works, then you know that your config file is OK

ersw1187 commented 9 years ago

Next try to run it with the -n option. This will only use the e-mail addresses you have entered in your config file.

jamespardon commented 9 years ago

Great! Running with the -t option works sending to myself, does that help pinpoint the problem?

bstascavage commented 9 years ago

Go to 'http://< your_plex_server_ip >:32400/pms/friends/all' and paste the results here.

jamespardon commented 9 years ago

I actually get 404 not found for that, screenshot_56

Usual plex site that works for me is : screenshot_57

bstascavage commented 9 years ago

It sounds like you cannot reach your own Plex server from the machine running the script. 404 means that it isn't reachable for whatever reason. This isn't an issue with the script

bstascavage commented 9 years ago

Try running it on the same machine as the Plex server, changing your 'server' parameter to 'localhost'

ersw1187 commented 9 years ago

Brian I just tested it both ways (IP and localhost). When I run it as you suggested, it runs into a #401 error because it can't set up a secure connection. I did get the xml list by running the following https://plex.tv/pms/friends/all

bstascavage commented 9 years ago

You are right, I looked at this too quickly.

What is the output of that XML?

jamespardon commented 9 years ago

Was testing from the plex media server mac itself, localhost is same result. https://plex.tv/pms/friends/all for me shows -

image

ersw1187 commented 9 years ago

Brian, I just sent you the example of my file via e-mail

ersw1187 commented 9 years ago

James, are you logged in to plex.tv? When I run it , it shows all the friends that also appear when I approach my server through plex.tv

ersw1187 commented 9 years ago

it looks something like this pms-friends

jamespardon commented 9 years ago

Yep, If I goto plex.tv and settings this is my screenshot :

image

If I type the address https://plex.tv/pms/friends/all I get the XML screenshot above. If I navigate to friends through plex.tv I get this address and screenshot -

image

is it as I have no shared libraries?

bstascavage commented 9 years ago

I am pretty sure your API key is incorrect. The script cannot connect to plex.tv.

To verify, update your script to the newest code. I added a check to throw an error to the log and cleanly exit if it cannot connect to plex.tv

jamespardon commented 9 years ago

Ok will do, when I view the config to get my API key there are 6 references to my plex server with different API keys, does this sound right?

bstascavage commented 9 years ago

Plex does not make it easy to get your API key. I am in the process of making that more simple and 'behind the scenes'. For me, when you look up your devices, it was the only one with the field 'provides="server"'

Does that help?

jamespardon commented 9 years ago

Yes that narrows it down to 1! I'll try that now

jamespardon commented 9 years ago

Switched to that API key and tried script again

ruby plexReport.rb /Users/jamespardon/Documents/PlexReport/PlexReport/bin/mailReport.rb:54:in sendMail': undefined methodeach' for nil:NilClass (NoMethodError) from plexReport.rb:346:in main' from plexReport.rb:350:in

'

This is with the latest script

bstascavage commented 9 years ago

I don't think it is. That error shouldn't show up with the latest script at all.

Put here the contents of bin/plexTv.rb

jamespardon commented 9 years ago

!/usr/bin/ruby

require 'rubygems' require 'json' require 'httparty'

Class To interact with Plex.tv

#

Author: Brian Stascavage

Email: brian@stascavage.com

# class PlexTv include HTTParty

base_uri 'http://plex.tv/'
format :xml

def initialize(config)
    $token = config['plex']['api_key']
end

def get(query, args=nil)
    if args.nil?
      new_query = query + "?X-Plex-Token=#{$token}"
    else
      new_query = query + "?X-Plex-Token=#{$token}&#{args}"
    end

    response = self.class.get(new_query, :verify => false)

    if response.code != 200
        $logger.error("Cannot connect to plex.tv!  Change your connection and your Plex API key.  Exiting.")
        exit
    end
    return response
end

end

bstascavage commented 9 years ago

And the end of your log file?

jamespardon commented 9 years ago

The log file shows the movies matching, the errors im pasting are from the terminal window i'm launching script from:

image

ersw1187 commented 9 years ago

what you could also try is create a plex user and invite it through plex.tv. It should show in the 'friends' screen on plex.tv and is suspect that it will also receive the e-mail. Brian is the script falling because it is getting no data thus NULL?

bstascavage commented 9 years ago

I mean,paste the end of your log file here

jamespardon commented 9 years ago

I, [2015-02-11T15:42:02.679776 #76622] INFO -- : Reporting Movie: The Love Punch E, [2015-02-11T15:42:02.705413 #76622] ERROR -- : Movie Stary Eyed using incompatiable agent I, [2015-02-11T15:42:04.123080 #76622] INFO -- : Reporting Movie: The Theory of Everything I, [2015-02-11T15:42:05.495313 #76622] INFO -- : Reporting Movie: Whiplash I, [2015-02-11T15:47:36.109725 #76816] INFO -- : Script complete. Ran in 15.776762 seconds

bstascavage commented 9 years ago

Update it again and run it with the '-v' flag

bstascavage commented 9 years ago

and paste the end of your log file

jamespardon commented 9 years ago

Is this enough of the log ?

@response=#<Net::HTTPOK 200 OK readbody=true>, @headers={"content-type"=>["text/xml;charset=utf-8"], "content-length"=>["2430"], "connection"=>["close"], "x-plex-protocol"=>["1.0"], "cache-control"=>["no-cache"]}> D, [2015-02-11T16:13:47.349266 #76878] DEBUG -- : Debug info for plexmediaserver connection D, [2015-02-11T16:13:47.349325 #76878] DEBUG -- : 200 D, [2015-02-11T16:13:47.349352 #76878] DEBUG -- : #<HTTParty::Request:0x007fee1939cee8 @http_method=Net::HTTP::Get, @path=#<URI::Generic:0x007fee1939cd30 URL:/library/metadata/923>, @options={:limit=>5, :assume_utf16_is_big_endian=>true, :default_params=>{}, :follow_redirects=>true, :parser=>HTTParty::Parser, :connection_adapter=>HTTParty::ConnectionAdapter, :base_uri=>"http://192.168.1.90:32400", :format=>:xml, :headers=>{"X-Plen-Token"=>"zDyrQN9K4i6ke3XfBW8P", "X-Plex-Token"=>"zDyrQN9K4i6ke3XfBW8P"}}, @last_uri=#<URI::HTTP:0x007fee193a7d98 URL:http://192.168.1.90:32400/library/metadata/923>, @raw_request=#, @last_response=#<Net::HTTPOK 200 OK readbody=true>>

bstascavage commented 9 years ago

Do you see anywhere in there that says "Plextv Response code" ?

jamespardon commented 9 years ago

No nothing at all

jamespardon commented 9 years ago

I'm on PMS version 0.9.9.7.429 if that helps

bstascavage commented 9 years ago

Wait a second...you have no Plex friends, right?

bstascavage commented 9 years ago

Try the newest code.

jamespardon commented 9 years ago

Correct no friends in Plex Newest code results : /Users/jamespardon/Documents/PlexReport/plexReport/bin/mailReport.rb:59:in []': no implicit conversion of String into Integer (TypeError) from /Users/jamespardon/Documents/PlexReport/plexReport/bin/mailReport.rb:59:inblock in sendMail' from /Users/jamespardon/Documents/PlexReport/plexReport/bin/mailReport.rb:58:in each' from /Users/jamespardon/Documents/PlexReport/plexReport/bin/mailReport.rb:58:insendMail' from PlexReport.rb:346:in main' from PlexReport.rb:350:in

' Quantum:bin jamespardon$

With -V the end of log D, [2015-02-11T22:19:02.137842 #86560] DEBUG -- : Debug info for plexmediaserver connection D, [2015-02-11T22:19:02.137892 #86560] DEBUG -- : 200 D, [2015-02-11T22:19:02.137920 #86560] DEBUG -- : #<HTTParty::Request:0x007f894e1b7ef0 @http_method=Net::HTTP::Get, @path=#<URI::Generic:0x007f894e1b7d10 URL:/library/metadata/2443>, @options={:limit=>5, :assume_utf16_is_big_endian=>true, :default_params=>{}, :follow_redirects=>true, :parser=>HTTParty::Parser, :connection_adapter=>HTTParty::ConnectionAdapter, :base_uri=>"http://192.168.1.90:32400", :format=>:xml, :headers=>{"X-Plen-Token"=>"zDyrQN9K4i6ke3XfBW8P", "X-Plex-Token"=>"zDyrQN9K4i6ke3XfBW8P"}}, @last_uri=#<URI::HTTP:0x007f894e1b65f0 URL:http://192.168.1.90:32400/library/metadata/2443>, @raw_request=#, @last_response=#<Net::HTTPOK 200 OK readbody=true>>

bstascavage commented 9 years ago

This should now be fixed.

jamespardon commented 9 years ago

/Users/jamespardon/Documents/PlexReport/plexReport/bin/mailReport.rb:58:in sendMail': undefined methodeach' for nil:NilClass (NoMethodError) from plexreport.rb:346:in main' from plexreport.rb:350:in

'

Not to worry, the -t is enough for me. Thanks for taking the time