Passing input into Curl command inside python3

99 Views Asked by At

I'm currently working with errbot, but i'm having trouble with allowing users to enter a message to be passed along with the curl command. my plugin looks as follows:

@arg_botcmd('team_key', type=str)
@arg_botcmd('--message' , dest='message', type=str)
def oncall_page(self, msg, team_key=None, message=None):
  if team_key in page_list.keys():
     team_id = page_list[team_key]
     data = {"message_type":"CRITICAL","state_message":"{0}".format(message)}                                     
     response = requests.post('https://www.apiurl.com/{0}'.format( team_id), data)
     yield "Paging {0} ".format( team_id )

My issue is with this line:

data = {"message_type":"CRITICAL","state_message":"{0}".format(message)}

This seems to be crashing the command completely, I'm hoping users can execute one command such as "!oncall page team_name --message "

Any help would be appreciated:)

1

There are 1 best solutions below

0
On
@arg_botcmd('team_key', type=str)
@arg_botcmd('--message' , dest='message', type=str)
def oncall_page(self, msg, team_key=None, message=None):
  if team_key in page_list.keys():
     team_id = page_list[team_key]
     text = str(message)
     msg_type = "critical"
     data = '{"message_type":"%s", "state_message":"%s"}' % (msg_type, text)
    # data = '{"message_type":"critical", "state_message":"%s"}'(text)
     URL = 'https://www.apiurl.com/{0}'.format( team_id)
     response = requests.post(URL , data) 

This is the fix for this!