Community
    • Categories
    • Recent
    • Popular
    • Users
    • Search
    • Register
    • Login

    POST Requests via Python

    Scheduled Pinned Locked Moved Entwicklung
    4 Posts 2 Posters 679 Views
    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.
    • A Offline
      andik
      last edited by

      kann mir jemand helfen - wenn ich z.B. via Insomnia den POST Request unten an https://idoit-test/src/jsonrpc.php schicke, dann klappt das mit dem Server anlegen.
      {
      "jsonrpc": "2.0",
      "method": "cmdb.object.create",
      "params": {
      "type": "C__OBJTYPE__SERVER",
      "title": "Testserver via API",
      "apikey": "xxxx"
      },
      "id": 1
      }

      wenn ich das gleiche mit dem Python Code unten versuche, passiert gar nichts

      import urllib.parse
      import urllib.request

      url = 'https://idoit-test/src/jsonrpc.php'
      values = {'jsonrpc': '2.0', 'method': 'cmdb.object.create', 'params': {'type': 'C__OBJTYPE__SERVER', 'title': 'Testserver via API', 'apikey': 'xxxx'}, 'id': 1}

      data = urllib.parse.urlencode(values)
      req = urllib.request.Request(url, data.encode('utf-8'))
      response = urllib.request.urlopen(req)
      the_page = response.read()

      GET Request via Python funktionieren problemlos.

      1 Reply Last reply Reply Quote 0
      • F Offline
        franknagel
        last edited by

        Das URL-Encoding sieht für mich falsch aus. Ich würde mal etwas in die Richtung

        import json
        import urllib.request
        
        url = 'https://idoit-test/src/jsonrpc.php'
        values = {'jsonrpc': '2.0', 'method': 'cmdb.object.create',
                  'params': {'type': 'C__OBJTYPE__SERVER', 'title': 'Testserver via API', 'apikey': 'xxxx'},
                  'id': 1}
        
        req = urllib.request.Request(url, json.dumps(values).encode('ASCII'))
        response = urllib.request.urlopen(req)
        the_page = response.read()
        

        probieren.

        1 Reply Last reply Reply Quote 0
        • A Offline
          andik
          last edited by

          danke für das Feedback. Deine Version läuft auch fehlerfrei durch, ein Objekt wieder aber leider nicht angelegt 😞

          1 Reply Last reply Reply Quote 0
          • F Offline
            franknagel
            last edited by

            Da fehlt wohl noch der content-type: application/json header.

            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
            • First post
              Last post