Retrying connection from mkai

Squashed and merged changes from @mkai. This includes some PEP8 fixes and retrying GET, PUT and DELETE operations.