Reputation: 33
In a whole context of trying to combine 2 APIs, I need to "combine" two functions results so that everything is more organized.
def descr():
return 88
def name():
return 'Account',descr()
When I print name(), I get this ('Account', 88). Problem with that format is that I can't use this result later in my script.
Here is the whole script :
import requests
import json
url = "https://proxy6.net/api/xxx/getproxy"
def descr():
return 88
def name():
return 'Account',descr()
querystring = {"descr":descr()}
headers = {
'Cache-Control': "no-cache",
'Postman-Token': "xxxx"
}
response = requests.request("GET", url, headers=headers, params=querystring)
data = response.json()
for value in data['list'].values():
host = value['host']
port = value['port']
url = "https://api.multiloginapp.com/v1/profile/create"
querystring = {"token":"xxx"}
payloadobj = {
"generateZeroFingerprintsData": True,
"name": name(),
"OS": "MacOS",
"platform": "MacIntel",
"browserType": "mimic",
"proxyHost": host,
"proxyPort": port,
"proxyIpValidation": False,
"proxyType": "socks5",
"maskFonts": True,
"disablePlugins": True,
"disableWebrtcPlugin": True,
"disableFlashPlugin": True,
"canvasDefType": "noise",
"hardwareConcurrency": 2,
"langHdr": "en-US,en;q=0.8",
"timeZone": "US/Eastern",
"audio": {
"noise": True
},
"geolocation": {
"permitType": "block"
},
"mediaDevices": {
"audioInputs": 1,
"audioOutputs": 1,
"videoInputs": 1
},
"webgl": {
"noise": True
},
"webRtc": {
"type": "block"
},
"shared": False
}
payload = json.dumps(payloadobj)
headers = {
'Content-Type': "application/json",
'Cache-Control': "no-cache",
'Postman-Token': "xxx"
}
response = requests.request("POST", url, data=payload, headers=headers, params=querystring)
print(response.text)
I want the name value in the JSON query above to be the result of name + descr, but it won't work with that returned format.
Upvotes: 0
Views: 64
Reputation: 1
If you are using python3.6 or later you can:
def descr():
return 88
def name():
return f"Account {descr()}"
Upvotes: 0
Reputation: 13
name()
is returning a tuple object not a string. To return a string you could change it to:
def name():
return "Account {}".format(descr())
Upvotes: 1
Reputation: 82765
Looks like you need.
def descr():
return 88
def name():
return '{} {}'.format('Account', descr())
print(name())
Output:
Account 88
Upvotes: 1