Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

callrestapi under sharedfunctions.py should return result as compare to print #26

Open
sarveshsood opened this issue Oct 17, 2019 · 3 comments
Assignees

Comments

@sarveshsood
Copy link

Hi,

I have been using callrestapi functions under sharedfunctions.py for multiple scenarios and it works fine when that functionality is running for the first time and returns results back and I extract the desired information to make it readable, however, when I re-running it, it's printing the error in JSON format in the console itself. It should return the value so that we can extract and format it properly to list the issues in a readable format.

Thanks,
Sarvesh

@gerrynelson63 gerrynelson63 self-assigned this Oct 17, 2019
@gerrynelson63
Copy link
Member

Sarvesh,

I am not sure I fully understand the issue. Can you provide more information and/or your code so that I can look into it.

Gerry

@sarveshsood
Copy link
Author

Hi Gerry,

If you see below code, under the condition "400 <= ret.status_code <=599", it's just print the result and in another scenario, it passes "result=ret.text".

# response error if status code between these numbers   
if (400 <= ret.status_code <=599):
   print(ret.text)    
   result=None            
   if stoponerror: sys.exit()  

# return the result    
else:
     # is it json   
     try:            
         result=ret.json()
     except:
        # is it text
        try:
            result=ret.text
        except:
            result=None
            print("NOTE: No result to print")            
return result;

In my scenario, if there is no error, it ran perfectly fine. However, if there is an error in the process, it prints the error but doesn't pass on the result to the main function.

@gerrynelson63
Copy link
Member

Ok, thanks I understand now. That is by design, if there is an error we print the error and we do return the result, but it is set to "None". But I see what you are saying it might be nice to return the error also to the calling program.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants