How to concatenate string with HTML for PUT request in Python?

Viewed 312

My current code is :

import requests
import base64
import pandas as pd

pat = 'TO BE FILLED BY YOU'  #CONFIDENTIAL
authorization = str(base64.b64encode(bytes(':'+pat, 'ascii')), 'ascii')

headers = {
    'Accept': 'application/json',
    'Authorization': 'Basic '+authorization
}

df = pd.read_csv('sf_metadata.csv')  #METADATA OF 3 TABLES CURRENCY,SALES,SF_INVENTORIES
df.set_index('TABLE_NAME', inplace=True,drop=True)
df_test1 = df.loc['CURRENCY'] 

x1 = df_test1.to_html()  # CONVERTING TO HTML TO PRESERVE THE TABULAR STRUCTURE

#JSON FOR PUT REQUEST
SamplePage1 = {
  "content": x1
}

#API CALLS TO AZURE DEVOPS WIKI 
response = requests.put(
    url="https://dev.azure.com/xxx/DIFTEST/_apis/wiki/wikis/xxx.wiki/pages?path=SamplePag1&api-version=6.0", headers=headers,json=SamplePage1)

I am able to get the following output:

enter image description here

I have a variable :

str1 = "View HIST_DUMPS - Dispatch Dump Record\nDatabase name : PROD_WG\nSchema name : MineOPs"

I need to concatenate str1 with x1 so that my output (after executing PUT request) will look like the below: enter image description here Can anyone assist me how can i achieve this. Thank you.

1 Answers

You can simply append your str1 and x1 strings together using the + operator for string concatenation and update the json dict

I have updated the str1 to use html in the example below

str1 = "<h1>View HIST_DUMPS - Dispatch Dump Record</h1><br><p><b>Database name</b> : PROD_WG<br><b>Schema name:</b> MineOPs</p>"

table_with_title = str1 + x1
#JSON FOR PUT REQUEST
SamplePage1 = {
  "content": table_with_title 
}

#API CALLS TO AZURE DEVOPS WIKI 
response = requests.put(
    url="https://dev.azure.com/xxx/DIFTEST/_apis/wiki/wikis/xxx.wiki/pages?path=SamplePag1&api-version=6.0", headers=headers,json=SamplePage1)

Output produced like below (table not visible in snip):

enter image description here

Related