The aim of this playbook🏁 is to outline general steps for exception handling of Python requests module.

1. Steps

  1. create & assign a response object within a try block
  2. call response.raise_for_status() right underneath (for 4xx & 5xx)
  3. create an exception block with requests.exceptions.RequestException base class
  4. pretty print out the exception

2. Contexts

2.1. error types and 2 notes

  • Have a look at the Requests exception docs -
  • Memorize these four exception types
  • If need be, dedicate an exception block to each
  • NOTE1: HTTPError is also raised…

The aim of this playbook🏁 is to define a command that lists all branches in the order they were manipulated (in a descending fashion).

sources


usecase

The aim of this playbook🏁 is to find the easiest way of getting the name of a branch that was deleted. In particular, when following a naming convention of <issueTrackerID_description>.

steps

  1. (git reflog > reflog.md) | Invoke-Item → the log opens in your markdown editor
  2. ctrl-f for the issueTrackerID → [copy]
  3. git checkout -b [paste]
  • or even easier, a single-stepper git reflog | Select-String <issue trackerID>

The aim of this playbook🏁 is to list steps for extracting all regex matches with Python’s re module.

  1. import re module
  2. define regex and assign it within the regex compile object with reg = re.compile(<regex>). You of course need to define a capture group to be extracted I.e. with http://pavol.kutaj.com/assets/(.*jpg|.*png) — only the image…

The aim of this playbook🏁 is to outline the step back when navigating relatively with Python.

1. steps for step-back

  1. __file__ returns the absolute path of the script
  2. os.path.dirname(__file__) returns the abs path of its parent folder (project root)
  3. os.path.join() concatenates the previous, with step-back control statement, and target folder
  4. os.path.abspath() normalizes

2. on os.path.join()

  • there are two control statements
  • . do nothing
  • .. step-back
  • Do not combine paths using string concatenation +
  • Use only os.path.join()
  • Why? Different computers represent paths in different ways.
  • E.g. Windows uses \ as a…


The aim of this explainer💡 is to look at the ways python’s version should be checked. The story is that my script required Python3 and has Python3-specific syntax.

1. steps/?

  • there is a version-checker
  • this is the error with Python2
  • the version checker could only work if…

The aim of this playbook🏁 is to learn how text is to be quickly matched in text files with python

1. steps

  1. open file with with open(<fileName>, <mode>, <encoding>) as fileAlias
  2. write a predicate expression with <string>, in operator and fileAlias.read()

2. example

  • I run unit tests with this checking if the item is deleted properly from an index file (a manifest table of the knowledge base)

3. sources


The aim of this explainer💡 is to get how to bring the merge conflicts from PR back into VSCode

1. steps/?

  • I encounter merge conflicts within Pull Requests
  • I want this to open as a git merge conflict in VSCode with the help of its codeLens — there is no “button” to do this in GitHub!
  • … and worse, not even in its PR extension, not in the GUI, just a tedious manual editor
  1. git checkout master
  2. run git merge <branch> → select a branch you want to merge into master
  3. now — you can deal with the merge hell from the git side-bar → Merge Changes
  4. make the changes with the help of codeLens
  5. commit changes → merged

Done + the PR disappears, too.

2. sources


The aim of this explainer💡 is to an examination of you can update all git branches with a single command.

  • There is git pull --all - but it fetches changes in all remote branches and then merges only the currently checked out one.
  • For an update of another branch, you need to check it out and merge changes

1. question

  • have 3 remote branches: master, staging and production — I have 3 local branches that track those remote branches.
  • updating all my local branches is tedious:

The aim of this how-to-guide🏁 is to be a go-to for Python Requests Module exception handling

1. 4 error types and 2 notes

  • NOTE1: HTTPError is also raised by Response.raise_for_status() if the HTTP Request returned an unsuccesful status code (4xx or 5xx)
  • NOTE2: exceptions that Requests explicitly raises inherit from requests.exceptions.RequestException

2. Base Class Exception

  • You can either catch the base-class exception, which will handle all cases:

3. Stack Overflow Example

  • Or you can catch them separately and do different things.

Pavol Kutaj

work stuff I am memorizing with anki. mostly python | technical support engineer; snowplow analytics | ⚔️ sedis animi est in memoria

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store