Welcome to the Pycom forum Forum
    • \[\[global:header.categories\]\]
    • \[\[global:header.recent\]\]
    • \[\[global:header.tags\]\]
    • \[\[global:header.popular\]\]
    • Login

    Explore Pybytes | Official Documentation | Report a Firmware Bug/Issue | GitHub

    Error posting data to my server

    Scheduled Pinned Locked Moved WiPy 2&3
    3 Posts 2 Posters 40 Views 2 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.
    • E Offline
      ecabanas
      last edited by

      Hi

      I'm using this code to post a json to my server. In Arduino we use HTTP client using this variables:

      char server[] = "********.com";
      char path[] = "/api/v2/gprs";
      int port = 11880;

      In the request library I changed the default port 80 in HTTP to 11880
      urequest.py

      def request(method, url, data=None, json=None, headers={}, stream=None):
          try:
              proto, dummy, host, path = url.split("/", 3)
          except ValueError:
              proto, dummy, host = url.split("/", 2)
              path = ""
          if proto == "http:":
              port = 11880
          elif proto == "https:":
              import ussl
              port = 443
          else:
              raise ValueError("Unsupported protocol: " + proto)
      

      main.py

      import os
      import pycom
      import machine
      import time
      import ujson
      import urequests
      from network import WLAN
      wlan = WLAN(mode=WLAN.STA)
      # Configure first UART bus to see the communication on the pc
      uart = machine.UART(0, 115200)
      
      # Configure second UART bus on pins P3(TX1) and P4(RX1)
      uart1 = UART(1, baudrate=115200) # 9600 baudrate also causes the same problem
      # Init WLAN
      try:
        wlan.connect(ssid="******", auth=(WLAN.WPA2, "*********"))
        while not wlan.isconnected():
          time.sleep_ms(50)
          print(wlan.ifconfig())
      
        print("WLAN connection on ...")
      except:
        print("[WLAN] try() (except). reset board.")
      
      data_set = {"dot":"gsm001","data":{"5":0,"6":999,"7":0,"14":3.0832,"31":0,"32":0,"33":0,"35":22,"38":300,"39":-50,"40":300,"42":300}}
      jsondump= ujson.dumps(data_set)
      urequests.request("POST","http://********.com/api/v2/gprs",data = jsondum, None, {"Content-Type": "application/json"},None).text
      

      but I got the following error:

      WiFi connection established
      MQTT ERROR! function got multiple values for argument 'user'
      ERROR! Could not connect to Pybytes!
      Pybytes configuration read from /flash/pybytes_config.json
      Traceback (most recent call last):
        File "main.py", line 27, in <module>
      SyntaxError: non-keyword arg after keyword arg
      Pycom MicroPython 1.20.2.r2 [v1.11-3a7776d] on 2020-11-23; GPy with ESP32
      

      Any idea what I'm doing wrong? I'm a newbie in pycom code, sorry

      thank's

      J 1 Reply Last reply Reply Quote 0
      • J Offline
        jcaron @ecabanas
        last edited by

        @ecabanas If you don't use Pybytes you probably want to disable it with pycom.pybytes_on_boot(False) to avoid confusing messages.

        The issue is that you have a mix of arguments with explicit names (name =) and without in your call to urequests.request.

        Either use names for all args (method="POST", url="...", data=jsondum, json=None, headers={"Content-Type": "application/json"}, stream=None — in which case you can actually skip those where your argument matches the default) or don't use any and just respect the order (i.e. just remove data=).

        1 Reply Last reply Reply Quote 0
        • E Offline
          ecabanas
          last edited by

          Hi @jcaron
          WOW!!! thanks now is working perfect!!!

          Thanks again!!!

          1 Reply Last reply Reply Quote 0

          Hello! It looks like you're interested in this conversation, but you don't have an account yet.

          Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

          With your input, this post could be even better 💗

          Register Login
          • 1 / 1
          • First post
            Last post

          Pycom on Twitter

          Pycom