POST with python request module





page_id  is coming from the response

call the function
        # -- create a new page
        page_id, response_code, resp_text = jlk.create_a_new_page(urlbase, auth, spaceKey, parent_id, dicyaml['Title'],
                                                                  filename, cleanedpath, mydebug)
        print(" tier page create page_id:", page_id, " and response_code:", response_code)



        # -- upload the page , get the dcitionary of file
        limage = dicyaml['Image']

        # -- loop thru the dictionary
        for i in range(len(limage)):
            filename = limage["imag"+str(i+1)]

        # -- call function to upload attachment
        response_code, dresponse_text = jlk.add_attachment_page(urlbase, auth, page_id, filename,imagepath)
        print("results response:",response_code,"\n response text:", dresponse_text)

code
def add_attachment_page(urlbase, auth, page_id, filename, path):
    """
    Will add an attachement to a page in confluence
    :param urlbase:
    :param auth:
    :param page_id:
    :param filename: image filename wit the path
    :return: 200 response_code
    """

    print("\t---- Start add_attachment_page() ----\n")

    # local variables
    url = urlbase + "/rest/api/content/"+ page_id + "/child/attachment"
    files = {'file': open(path + "\\" + filename, 'rb')}

    # -- create the header and body of the request message
    headers = {
        "X-Atlassian-Token": "nocheck"
    }

    response = requests_jlk.post(
        url,
        headers=headers,
        auth=auth,
        verify=False,
        files=files
    )
    dresponse_text = json.loads(response.text)

    print("---- End of:  add_attachment_page() ----\n")
    return (response.status_code,dresponse_text)