brent timothy saner via plug on 18 Feb 2021 10:43:03 -0800


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Re: [PLUG] Slightly off topic, debugging python


On 2/18/21 13:01, Michael Lazin via plug wrote:
> I wrote a script which makes api calls over the internet and I am
> getting unexpected results.  It is making a  web request.  I am using
> pycharm.  Can anyone tell me how to set pycharm for verbose output so I
> can see the web server's response code?  I suspect that I am getting an
> http error code which causes the unexpected output.  I hope that this
> isn't too much to ask.  I am an experienced Linux user but I am new to
> python programming.  Thanks for your help.
> 
> Sincerely,
> 
> Michael Lazin 
> 

PyCharm is an IDE, and python doesn't have a "verbose" mode. It's as
verbose as you specify your calls.

I'm assuming you're using requests since it's kind of the gold standard
for HTTP/HTTPS stuff.


Assuming your request is called via e.g.

req = requests.get('https://some.domain.tld/some/url', data = {'foo':
'bar'})

then you can access the HTTP status return code via:

req.status_code

You can access the content of the error page via req.content, headers
via req.headers, etc.

There's a shorthand for request responses, though. req.ok is a boolean
that's True if the call returns a 200, 301, or 302 (and maybe a couple
others - all "success" statuses in various forms) and False indicates
anything else.
___________________________________________________________________________
Philadelphia Linux Users Group         --        http://www.phillylinux.org
Announcements - http://lists.phillylinux.org/mailman/listinfo/plug-announce
General Discussion  --   http://lists.phillylinux.org/mailman/listinfo/plug