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
#2
If you have formatting in your code, we can't copy it and run it to see what the problem is.

Without running it, I would say that I don't see where you call the createProject function. You have to call a function after you create it to get it to do anything, like you call main.

The global statement should not be used here. You should return values from your function (with a return statement) instead.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply
#3
In addition,
  • Use now.strftime() to produce the string you need
  • Use the requests module instead of urllib2
Unless noted otherwise, code in my posts should be understood as "coding suggestions", and its use may require more neurones than the two necessary for Ctrl-C/Ctrl-V.
Your one-stop place for all your GIMP needs: gimp-forum.net
Reply
#4
(Feb-15-2017, 01:51 AM)ichabod801 Wrote: If you have formatting in your code, we can't copy it and run it to see what the problem is.

Without running it, I would say that I don't see where you call the createProject function. You have to call a function after you create it to get it to do anything, like you call main.

The global statement should not be used here. You should return values from your function (with a return statement) instead.

HI, I am not sure what you mean by formatting , I dont think I have formatting, but cant you copy paste this in your editor? Like I said I am new to python and I thought I have defined the function createProject, so if you could please fix ( give me  an example within this code) what I done wrong and send it back to me so I can run it and see
Thanks.
Pasi
Reply
#5
Please see https://python-forum.io/misc.php?action=help&hid=25
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Python loop for posting data to web marciokoko 10 1,479 Aug-26-2023, 02:17 AM
Last Post: deanhystad
  Problem posting image to clipboard noel 0 2,126 Sep-26-2020, 10:50 AM
Last Post: noel
  module logging posting randomly DJ_Qu 2 2,187 May-14-2019, 06:41 AM
Last Post: DJ_Qu
  Posting zip file on HTTP network using Python2.7 deepti92 1 6,748 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