Python Forum
Need help with posting to API website
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Need help with posting to API website
#1
HI ,

I am pretty new to python and wanted help with below code? All I am trying to do is to make a project name and post it to API website. Not sure if my code is correct? This is not working, I don’t grt any error s but the code look slike by passess the createPRoject portion and ends with no errors?

Process finished with exit code 0

Thanks a bunch!
Pasi
import datetime

from pip._vendor import requests

import requests

import urllib2

import glsapiutil

import urllib

import _auth_tokens

globals()

TODAY = ""





def getToday():

   now = datetime.datetime.now()



   strToday = str(now.year) + "-"

   tmp = str(now.month)

   if len(tmp) == 1:

       tmp = "0" + tmp

   strToday += (tmp + "-")

   tmp = str(now.day)

   if len(tmp) == 1:

       tmp = "0" + tmp

   strToday += tmp



   return strToday



encoding = "utf-8"





def createProject (pName, udfs , pDate):

   print (pName, udfs, pDate)

#    print(pName, udfs, pDate)

   global r

   global post_response

   global d

   r.encoding = "utf-8"
   pName = "Prj123"
   udfs = “UT231”
   pDate = getToday()

   url1Project = "mytestdotcom/ri/project"
   urludfs = ' mytestdotcom/ri/userdefined'
   pName = "Prj123"

   post_data = {'username': "ra", 'password': "mypasswrd"}
   post_response = requests.post("testdotcom/api/v2/projects", data=post_data)
   r = requests.post(url1Project, data=createProject)
   print (r.text)

#  print response


def main():
         global api
   #     global ARGS
         api = glsapiutil.glsapiutil()
#          api.setup(_auth_tokens.API_USERNAME, _auth_tokens.API_PASSWORD)

#     #api.setURI(args.stepURI)
#     #api.setup(args.username, args.password)
#     global TODAY
#     api = glsapiutil.glsapiutil()
if __name__ == "__main__":
   main()
Reply


Messages In This Thread
Need help with posting to API website - by pasi12 - Feb-15-2017, 01:04 AM
RE: Need help with code - by ichabod801 - Feb-15-2017, 01:51 AM
RE: Need help with code - by pasi12 - Feb-15-2017, 04:14 PM
RE: Need help with code - by Ofnuts - Feb-15-2017, 08:17 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Python loop for posting data to web marciokoko 10 1,562 Aug-26-2023, 02:17 AM
Last Post: deanhystad
  Problem posting image to clipboard noel 0 2,177 Sep-26-2020, 10:50 AM
Last Post: noel
  module logging posting randomly DJ_Qu 2 2,232 May-14-2019, 06:41 AM
Last Post: DJ_Qu
  Posting zip file on HTTP network using Python2.7 deepti92 1 6,799 May-15-2018, 12:41 PM
Last Post: deepti92

Forum Jump:

User Panel Messages

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