Python Forum

Full Version: Error: cannot mix str with (non-str) arguments
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello everyone,

I have a function that connects to an API and get data and needs 3 parameters, all string, but one of them is a GUID. So I validated what data type is the GUID coming with, and it is "text", but still get the error about mixing data types. Here is what the debugger returned when validating the data types which also shows the error message.

[attachment=3142]

is how I define the function inside my views.py file:

def GetRepoBranches(Org, Prj, RepoID):
URI = (f"https://dev.azure.com/{Org}/{Prj}/_apis/git/repositories/{RepoID}/refs")
return (requests.get(URI, userauth)).json()


To test the URI constructed in the function, I used PostMan and it worked ok (See attachment to view the whole URI).

[attachment=3141]

The interesting thing is, when I run the following code without using the function, and passing the same values when building the URI, it works ok:

URI = (f"https://dev.azure.com/{Org}/{Prj}/_apis/git/repositories/{r['id']}/refs")
refsDetails = (requests.get(URI, auth=userauth)).json()


So, I do not know why I am getting that error when using the function. Any help would be greatly appreciated.

Thanks
NG
Please post code using bb tags and not images along with any errors.
requests.get(URI, userauth) passes userauth as the value for "params". According to the documentation:
Quote:requests.get(url, params=None, **kwargs)[source]
Sends a GET request.

Parameters:
url – URL for the new Request object.

params – (optional) Dictionary, list of tuples or bytes to send in the query string for the Request.

**kwargs – Optional arguments that request takes.

Returns:
Response object

Return type:
requests.Response
requests.get(URI, auth=userauth) passes userauth as the value for auth.

The first example doesn't work because userauth is not a dictionary, a list of tuples, or bytes.