Python Forum
Error: cannot mix str with (non-str) arguments
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Error: cannot mix str with (non-str) arguments
#1
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.

   

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).

   

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
Larz60+ write Dec-11-2024, 05:58 AM:
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
Reply
#2
Please post code using bb tags and not images along with any errors.
I welcome all feedback.
The only dumb question, is one that doesn't get asked.
My Github
How to post code using bbtags
Download my project scripts


Reply
#3
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.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Error TypeError: output_type_handler() takes 2 positional arguments but 6 were given paulo79 1 3,645 Oct-17-2022, 06:29 PM
Last Post: paulo79
  invalid keyword arguments error sagpal 3 3,493 Jun-04-2020, 10:24 PM
Last Post: bowlofred
  Function / Arguments / Error Help Ghosty 8 5,939 Jul-01-2018, 10:35 AM
Last Post: buran
  Functions (Arguments Passing,Changing a mutable ,Assignment to Arguments Names) Adelton 2 4,759 Mar-02-2017, 10:23 PM
Last Post: zivoni
  error: unrecognized arguments zafar202 2 50,215 Feb-08-2017, 02:50 PM
Last Post: zafar202

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020