I want to get a response from post request to a site that requires password and json data as input. The code looks like this:
import requests
from requests.auth import HTTPBasicAuth
import json
url = 'http://ssss.ct.xxx:9000/xxx.xx_xxx/xxxx/get/json/'
data = '''{"RowSelectors":[{"Name":"xx","Value":"100649","Operation":"OR" },
{"Name":"xx","Value":"577","Operation":"OR" }],"TableName":"YY"}'''
response = requests.post(url, data=json.loads(data), auth = HTTPBasicAuth('my_user', 'my_password'))
print(response)
And the print function shows me a "Response [415]", which is "Unsupported Media Type" error. I expect it to return me a result from the query in variable "data". I know that something might be wrong with this data, but I don't know how to solve this.
I also tried using another library:
import urllib.request
import urllib.parse
import json
data1 = '''{"RowSelectors":[{"Name":"xx","Value":"100649","Operation":"OR" },
{"Name":"xx","Value":"577","Operation":"OR" }],"TableName":"YY"}'''
data1= json.loads(data1)
params = urllib.parse.urlencode(data1)
x = urllib.request.Request('http://ssss.ct.xxx:9000/xxx.xx_xxx/xxxx/get/json/', data=params)
y= urllib.request.urlopen(x, data = params)
print(y.read())
But it doesn't work too. The error in this case is: POST data should be bytes, an iterable of bytes, or a file object. It cannot be of type str. And I don't understand the documentation on how i should include the user and password to this code.
Additional maybe useful info : I'm using soapUI and I have 3 inputs that I want to have. First is endpoint=http://ssss.ct.xxx:9000, then its resource=/xxx.xx_xxx/xxxx/get/json/ and the SQL query written in data. I expect my response to be a table in json.
I appreciate any help;)