• Register
    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search

    json rest problem

    Official EVOK API
    3
    15
    3736
    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.
    • J
      juntiedt last edited by tomas_hora

      I am trying to run the following code. Unfortunately no success.
      Apppreciate very much your support.

      Hannes

      import http.client
      
      payload = "{\"value\" : \"1\"}"
      headers = {'content-type': "application/json"}
      
      conn = http.client.HTTPConnection("localhost:8080")
      conn.request("POST", "/json/relay/%7B5%7D", payload, headers)
      response = conn.getresponse()
      print(response.status, response.reason)
      data = response.read()
      conn.close()
      
      print(data)
      

      Error report:

      Traceback (most recent call last):
        File "/home/pi/json_rest_0.py", line 7, in <module>
          conn.request("POST", "/json/relay/%7B5%7D", payload, headers)
        File "/usr/lib/python3.5/http/client.py", line 1107, in request
          self._send_request(method, url, body, headers)
        File "/usr/lib/python3.5/http/client.py", line 1152, in _send_request
          self.endheaders(body)
        File "/usr/lib/python3.5/http/client.py", line 1103, in endheaders
          self._send_output(message_body)
        File "/usr/lib/python3.5/http/client.py", line 934, in _send_output
          self.send(msg)
        File "/usr/lib/python3.5/http/client.py", line 877, in send
          self.connect()
        File "/usr/lib/python3.5/http/client.py", line 849, in connect
          (self.host,self.port), self.timeout, self.source_address)
        File "/usr/lib/python3.5/socket.py", line 712, in create_connection
          raise err
        File "/usr/lib/python3.5/socket.py", line 703, in create_connection
          sock.connect(sa)
      ConnectionRefusedError: [Errno 111] Connection refused
      
      1 Reply Last reply Reply Quote 0
      • T
        tomas_hora administrators last edited by

        @juntiedt Try it with:

        conn.request("POST", "/json/relay/5", payload, headers)
        

        and according to the

        File "/usr/lib/python3.5/http/client.py", line 849, in connect
          (self.host,self.port), self.timeout, self.source_address)
        

        it seems that the client cannot connect to the server (check the IP address and port) and if evok is running (systemctl status evok).

        1 Reply Last reply Reply Quote 0
        • J
          juntiedt last edited by

          Hi Tomas,

          when I use localhost:8080 I receive the very long error message above. However, when I use localhost:80 and your request I receive the error message below. Does this tell you something?

          regards
          Hannes

          import http.client
          
          payload = "{\"value\":\"1\"}" 
          headers = {'content-type':"application/json"}
          
          conn = http.client.HTTPConnection("localhost:80")
          conn.request("POST", "/json/relay/5", payload, headers)
          response = conn.getresponse()
          print(response.status, response.reason)
          data = response.read()
          print(data)
          conn.close()
          

          I get this respones:

          404 Not Found
          b'<html><title>404: Not Found</title><body>404: Not Found</body></html>'
          
          T 1 Reply Last reply Reply Quote 0
          • T
            tomas_hora administrators @juntiedt last edited by

            @juntiedt Are you sure that evok is running on localhost on port 8080?

            1 Reply Last reply Reply Quote 0
            • J
              juntiedt last edited by

              evoc is running. I checked it with "systemctl status evok"
              I checked "/etc/evoc.conf. port" which was set to 80. Actually I haven't changed anything since installation! Changed it now to 8080.
              I am getting the same response as before: 404 Not Found ... see above - but now on port 8080

              Is there another file where I should/could change the port to 8080?

              does body mean payload and title mean headers?

              T T 2 Replies Last reply Reply Quote 0
              • T
                TomasKnot @juntiedt last edited by

                This post is deleted!
                1 Reply Last reply Reply Quote 0
                • T
                  tomas_hora administrators @juntiedt last edited by

                  @juntiedt After you changed the port in /etc/evok.conf to 8080, did you restart it? I think it should not work, because there is the some webserver running on 8080. Check it with

                  netstat -putan
                  
                  1 Reply Last reply Reply Quote 0
                  • J
                    juntiedt last edited by

                    is it possible that I have a problem with tornadorpc-evok. I am not sure if it is installed the correct way. please let me know how to install it and where I can find the correct installation file.

                    regarding your question: no web server running

                    T 1 Reply Last reply Reply Quote 0
                    • T
                      tomas_hora administrators @juntiedt last edited by

                      @juntiedt Some server is running because it responds with 404... The tornado-rpc evok is part of evok itself. Please try to reinstall evok and paste the output of the installation script

                      1 Reply Last reply Reply Quote 0
                      • J
                        juntiedt last edited by

                        ok, I will reinstall evok.
                        Wich one would you recommend?
                        Legacy or Evok 2.0 on my unipi1.1 with stretch

                        T 1 Reply Last reply Reply Quote 0
                        • T
                          tomas_hora administrators @juntiedt last edited by

                          @juntiedt 2.0

                          1 Reply Last reply Reply Quote 0
                          • J
                            juntiedt last edited by

                            new stretch image, new evok --> all works perfectly!
                            thanks Tomas

                            1 Reply Last reply Reply Quote 0
                            • J
                              juntiedt last edited by

                              Hi Tomas,
                              I was too optimistic yesterday. Today I tryed your websocket based sample programm with Python 3. Python can't find websocket. Do I have to install a websocket library? If yes which one?

                              There is another problem I found when rebooting after installing evok.
                              During booting raspbian stretch I got this warning message:
                              "Failed to start load kernel modules"
                              Could this be the reason why websocket does not work?

                              I am running plain stretch with latest update and upgrade

                              1 Reply Last reply Reply Quote 0
                              • J
                                juntiedt last edited by

                                system Status:

                                ● systemd-modules-load.service - Load Kernel Modules
                                   Loaded: loaded (/lib/systemd/system/systemd-modules-load.service; static; vendor preset: enabled)
                                   Active: failed (Result: exit-code) since Fri 2017-11-17 12:50:58 CET; 2min 17s ago
                                     Docs: man:systemd-modules-load.service(8)
                                           man:modules-load.d(5)
                                  Process: 126 ExecStart=/lib/systemd/systemd-modules-load (code=exited, status=1/FAILURE)
                                 Main PID: 126 (code=exited, status=1/FAILURE)
                                
                                Nov 17 12:50:58 raspberrypi systemd-modules-load[126]: Inserted module 'i2c_dev'
                                Nov 17 12:50:58 raspberrypi systemd-modules-load[126]: Inserted module 'i2c_bcm2708'
                                Nov 17 12:50:58 raspberrypi systemd-modules-load[126]: Error running install command for unipi_eprom
                                Nov 17 12:50:58 raspberrypi systemd-modules-load[126]: Failed to insert 'unipi_eprom': No such file or directory
                                Nov 17 12:50:58 raspberrypi systemd-modules-load[126]: /etc/opt/unipi_eprom: 24: /etc/opt/unipi_eprom: cannot create /sys/class/i2c-dev/i2c-1/device/new_device: Directory none
                                Nov 17 12:50:58 raspberrypi systemd-modules-load[126]: sh: 1: cannot create /sys/bus/i2c/devices/i2c-1/new_device: Directory nonexistent
                                Nov 17 12:50:58 raspberrypi systemd[1]: systemd-modules-load.service: Main process exited, code=exited, status=1/FAILURE
                                Nov 17 12:50:58 raspberrypi systemd[1]: Failed to start Load Kernel Modules.
                                Nov 17 12:50:58 raspberrypi systemd[1]: systemd-modules-load.service: Unit entered failed state.
                                Nov 17 12:50:58 raspberrypi systemd[1]: systemd-modules-load.service: Failed with result 'exit-code'.
                                ~
                                
                                1 Reply Last reply Reply Quote 0
                                • J
                                  juntiedt last edited by

                                  sorry for the websocket issue. Its now running.

                                  the only thing left is the unipi_eprom problem in the boot process of Raspbian

                                  1 Reply Last reply Reply Quote 0
                                  • First post
                                    Last post