Python Forum
multiple values as parameters to POST command..
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
multiple values as parameters to POST command..
#3
Hi Thanks for your reply,

sorry, i am replying bit late and trying to put out various methods and failing :(

The actual context is i am trying to get some linux server status and posting to slack channel

In original post I have given the sample which is base code which i am trying to build correct code for my context

This is original code
from __future__ import print_function

import boto3
import json
import logging
import os
logging.basicConfig()

from urllib2 import Request, urlopen, URLError, HTTPError

# configuration

# The Slack channel to send a message to stored in the slackChannel environment variable
SLACK_CHANNEL = "#XXXXXXXXXX"
# Add the webhook URL from Slack below
HOOK_URL = "https://hooks.slack.com/services/xxxxx/xxxx/xxxxx"

response = conn.get_all_instances()
MESSAGE = response
# Setting up logging
logger = logging.getLogger()
logger.setLevel(logging.INFO)

slack_message = {
    'channel': SLACK_CHANNEL,
    'text': MESSAGE}

req = Request(HOOK_URL, json.dumps(slack_message))
try:
    response = urlopen(req)
    response.read()
    logger.info("Message posted to %s", slack_message['channel'])
except HTTPError as e:
    logger.error("Request failed: %d %s", e.code, e.reason)
except URLError as e:
    logger.error("Server connection failed: %s", e.reason)
So in above code line number 18 the variable "response" actually returns in below format
{
    "Reservations": [
        {
            "Instances": [
                {
                    "Monitoring": {
                        "State": "disabled"
                    },
                    "PublicDnsName": "",
                    "StateReason": {
                        "Message": "Client.UserInitiatedShutdown: User initiated shutdown",
                        "Code": "Client.UserInitiatedShutdown"
                    },
                    "State": {
                        "Code": 80,
                        "Name": "stopped"
                    },
                    "EbsOptimized": false,
                    "LaunchTime": "2018-02-08T10:37:36.000Z",
                    "PrivateIpAddress": "xx.xx.xx.xxx",
                    "ProductCodes": [],
                    "VpcId": "xxxxxx",
                    "StateTransitionReason": "User initiated (2018-02-08 11:13:34 GMT)",
                    "InstanceId": "xxxxxxx",
                    "EnaSupport": true,
                    "ImageId": "xxxxx",
                    "PrivateDnsName": "xxxxxxxx",
                    "KeyName": "xxxxxx",
                    "SecurityGroups": [
                        {
                            "GroupName": "xxxxxxxx",
                            "GroupId": "xx-xxxx"
                        }
                    ],
                    "ClientToken": "",
                    "SubnetId": "xxxx-xxxxx",
                    "InstanceType": "xx.xxx",
                    "NetworkInterfaces": [
so i want to post this information to slack channel in under stable way for readers

Hope I am giving right info.. can you please help..where i am doing it wrong...

The above code says json is not serializable error

Regargs
ASP
Reply


Messages In This Thread
RE: multiple values as parameters to POST command.. - by onenessboy - Feb-20-2018, 12:18 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  __init__() got multiple values for argument 'schema' dawid294 4 2,265 Jan-03-2024, 09:42 AM
Last Post: buran
  How to combine multiple column values into 1? cubangt 15 2,809 Aug-11-2022, 08:25 PM
Last Post: cubangt
  Substitue multiple substrings in one command Pavel_47 0 831 Jul-18-2022, 01:24 PM
Last Post: Pavel_47
  function accepts infinite parameters and returns a graph with those values edencthompson 0 855 Jun-10-2022, 03:42 PM
Last Post: edencthompson
  Function - Return multiple values tester_V 10 4,438 Jun-02-2021, 05:34 AM
Last Post: tester_V
  How to input & output parameters from command line argument shantanu97 1 2,552 Apr-13-2021, 02:12 PM
Last Post: Larz60+
  Xlsxwriter: Create Multiple Sheets Based on Dataframe's Sorted Values KMV 2 3,483 Mar-09-2021, 12:24 PM
Last Post: KMV
  Looking for help in Parse multiple XMLs and update key node values and generate Out.. rajesh3383 0 1,872 Sep-15-2020, 01:42 PM
Last Post: rajesh3383
  Assigning multiple values using tuple sivacg 2 2,265 Aug-06-2020, 10:29 PM
Last Post: perfringo
  Function parameters and values as string infobound 1 1,757 Jul-24-2020, 04:28 AM
Last Post: scidam

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020