• Recent
  • Tags
  • Unsolved
  • Solved
  • MagicMirror² Repository
  • Documentation
  • 3rd-Party-Modules
  • Donate
  • Discord
  • Register
  • Login
MagicMirror Forum
  • Recent
  • Tags
  • Unsolved
  • Solved
  • MagicMirror² Repository
  • Documentation
  • 3rd-Party-Modules
  • Donate
  • Discord
  • Register
  • Login
A New Chapter for MagicMirror: The Community Takes the Lead
Read the statement by Michael Teeuw here.

ECONNREFUSED when trying to get JSON from my server (MMM-json-feed)

Scheduled Pinned Locked Moved Troubleshooting
10 Posts 4 Posters 2.8k Views 3 Watching
Loading More Posts
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    toh1000
    last edited by toh1000 Feb 21, 2018, 9:51 PM Feb 21, 2018, 9:49 PM

    Hi all,
    I like to display a simple value that can be fetched from a JSON service. So I started with the MMM-json-feed module which is pretty much doing the trick with some test services that I found (e.g. http://ip.jsontest.com/).
    It seemed to need just a simple adaptation of the config file, to load the JSON data from an URL in my private network.
    Unfortunately this does not work, although my JSON service returns proper data (checked with my browser). The mm output is

    MMM-json-feed sending request: GET http://raspberrypi.fritz.box/temp/
    MMM-json-feed received
    MMM-json-feed Error: connect ECONNREFUSED 192.168.178.33:80
    Whoops! There was an uncaught exception...
    TypeError: Cannot read property 'statusCode' of undefined
        at Request._callback (/home/pi/MagicMirror/modules/MMM-json-feed/node_helper.js:15:48)
        at self.callback (/home/pi/MagicMirror/node_modules/request/request.js:186:22)
        at emitOne (events.js:96:13)
        at Request.emit (events.js:191:7)
        at Request.onRequestError (/home/pi/MagicMirror/node_modules/request/request.js:878:8)
        at emitOne (events.js:96:13)
        at ClientRequest.emit (events.js:191:7)
        at Socket.socketErrorListener (_http_client.js:358:9)
        at emitOne (events.js:96:13)
        at Socket.emit (events.js:191:7)
    MagicMirror will not quit, but it might be a good idea to check why this happened. Maybe no internet connection?
    If you think this really is an issue, please open an issue on GitHub: https://github.com/MichMich/MagicMirror/issues
    

    I thought it might relate to CORS and compared the headers of the JSONTest (http://ip.jsontest.com) and my JSON service. They both look quite similar. Nothing that make me believe there is something missing.
    JSONTest:

    Access-Control-Allow-Origin: *
    Cache-Control: private
    Content-Encoding: gzip
    Content-Length: 67
    Content-Type: application/json; charset=ISO-8859-1
    Date: Wed, 21 Feb 2018 21:08:30 GMT
    Server: Google Frontend
    Vary: Accept-Encoding
    X-Cloud-Trace-Context: f1d4981eae5655f530221b705a794f51
    
    Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
    Accept-Encoding: gzip, deflate
    Accept-Language: de,en-US;q=0.7,en;q=0.3
    Connection: keep-alive
    Host: ip.jsontest.com
    Upgrade-Insecure-Requests: 1
    User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:58.0) Gecko/20100101 Firefox/58.0
    
    

    My service:

    Access-Control-Allow-Origin: *
    Content-Length: 64
    Content-Type: application/json
    Date: Wed, 21 Feb 2018 21:08:06 GMT
    Server: CherryPy/13.1.0
    
    Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
    Accept-Encoding: gzip, deflate
    Accept-Language: de,en-US;q=0.7,en;q=0.3
    Cache-Control: max-age=0
    Connection: keep-alive
    Host: raspberrypi.fritz.box
    Upgrade-Insecure-Requests: 1
    User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:58.0) Gecko/20100101 Firefox/58.0
    
    

    Any guesses?

    E 1 Reply Last reply Feb 21, 2018, 10:55 PM Reply Quote 0
    • E Offline
      E3V3A @toh1000
      last edited by Feb 21, 2018, 10:55 PM

      @toh1000 Please post JSON response. I just spent a day trying to figure out why MM is so fickly regarding non-perfect JSON being sent over the socket. Loading JSON from a variable, just fine. Pushing the exact same JSON over a socket…had problems.

      BTW. Is it correct that it says your JSON is GZIP encoded, no??

      "Everything I do (here) is for free – altruism is the way!"
      MMM-FlightsAbove, MMM-Tabulator, MMM-Assistant (co-maintainer)

      N 2 Replies Last reply Feb 21, 2018, 11:03 PM Reply Quote 0
      • N Offline
        ninjabreadman @E3V3A
        last edited by Feb 21, 2018, 11:03 PM

        @toh1000 Can you reach the JSON service with curl on your MM machine? And @e3v3a is right – ideally put the response through a validator, especially for things like trailing commas.

        Problem with config or JavaScript? Copy/paste it into JSHint.
        Check out the detailed walkthroughs on install, config, modules, etc.

        T 1 Reply Last reply Feb 22, 2018, 9:48 PM Reply Quote 0
        • N Offline
          ninjabreadman @E3V3A
          last edited by ninjabreadman Feb 21, 2018, 11:29 PM Feb 21, 2018, 11:28 PM

          @E3V3A Also, @toh1000’s HTTP request included the header Accept-Encoding: gzip, deflate, so the test site responded with Content-Encoding: gzip. That’s totally appropriate, and usually this is handled transparently by the client, which will then provide the uncompressed response. However, the actual service (“My service”) responded with no compression.

          Problem with config or JavaScript? Copy/paste it into JSHint.
          Check out the detailed walkthroughs on install, config, modules, etc.

          1 Reply Last reply Reply Quote 0
          • E Offline
            E3V3A
            last edited by E3V3A Feb 22, 2018, 1:17 PM Feb 22, 2018, 1:17 PM

            From here:

            ECONNREFUSED (Connection refused): No connection could be made because the target machine 
            actively refused it. This usually results from trying to connect to a service that is inactive on the 
            foreign host.
            

            "Everything I do (here) is for free – altruism is the way!"
            MMM-FlightsAbove, MMM-Tabulator, MMM-Assistant (co-maintainer)

            T 1 Reply Last reply Feb 22, 2018, 9:51 PM Reply Quote 0
            • C Offline
              cowboysdude Module Developer
              last edited by Feb 22, 2018, 2:21 PM

              Here’s an example in my node helper I use to get json

              request({
                          url: "xxxxxxxxxxxx.json",
                          method: 'GET',
                          headers: {
                              'User-Agent': 'MagicMirror/1.0 (' + this.config.email + ')'
                          }
              
              T 1 Reply Last reply Feb 22, 2018, 10:01 PM Reply Quote 1
              • T Offline
                toh1000 @ninjabreadman
                last edited by Feb 22, 2018, 9:48 PM

                @ninjabreadman Yes, curl call returns correct json:

                {"Date": "22.02.2018", "Temperature": -0.187, "Time": "22:45:37"}
                
                1 Reply Last reply Reply Quote 0
                • T Offline
                  toh1000 @E3V3A
                  last edited by Feb 22, 2018, 9:51 PM

                  @E3V3A Any idea what I could do to accept the connection?

                  1 Reply Last reply Reply Quote 0
                  • T Offline
                    toh1000 @cowboysdude
                    last edited by Feb 22, 2018, 10:01 PM

                    @cowboysdude I added the header (without the this.config.email) but got the same result.

                    1 Reply Last reply Reply Quote 0
                    • T Offline
                      toh1000
                      last edited by Feb 22, 2018, 11:02 PM

                      Solved:
                      The problem was that the module translated the server name into an up address and CherryPy was not configured to response to that.
                      Reconfiguring did the trick:
                      this article explains how this is done
                      Thanks for your efforts.

                      1 Reply Last reply Reply Quote 0
                      • 1 / 1
                      1 / 1
                      • First post
                        1/10
                        Last post
                      Enjoying MagicMirror? Please consider a donation!
                      MagicMirror created by Michael Teeuw.
                      Forum managed by Sam, technical setup by Karsten.
                      This forum is using NodeBB as its core | Contributors
                      Contact | Privacy Policy