Tags

always handle errors

8:31pm on May 03, 2014

I made this pull request but the author of the library thinks that not bothering to check HTTP status codes is acceptable.

So my code goes from:

1
2
3
request_token, request_token_secret = self.oauth.get_request_token(method="POST")
auth_token = self.oauth.get_access_token(request_token, request_token_secret,method="POST")
self.session = self.oauth.get_session(auth_token)

To:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
from rauth.service import process_token_request
from rauth.utils import parse_utf8_qsl

rsp = self.oauth.get_raw_request_token(method="POST")
rsp.raise_for_status()
request_token, request_token_secret = process_token_request(rsp, parse_utf8_qsl, "oauth_token","oauth_token_secret")

rsp = self.oauth.get_raw_access_token(request_token, request_token_secret, method="POST")
rsp.raise_for_status()
auth_token = process_token_request(rsp, parse_utf8_qsl, "oauth_token", "oauth_token_secret")

self.session = self.oauth.get_session(auth_token)

It's not horrible, but really, why would you ever think it's OK to not handle errors?

bug or feature?

9:25pm on Apr 29, 2014

I've been writing an API for a little project I've been working on for a while, and in searching for a not-horrible way to do OAuth1 authentication, I actually found a Python library that doesn't suck.

Of course, it's not perfect. I noticed today that it doesn't actually handle HTTP error responses - it doesn't even check the return code at all, just assumes that any response it's given will be parseable. Which of course is not at all true in many cases - including in mine.

So of course I've forked it and am working on a fix.

you guessed it - another bug

12:37am on Apr 25, 2014

Found another bug and made a pull request - this time in the 'rauth' library, which does OAuth in a reasonable sane way.

Except for this issue - I still have no idea why they're trying to parse the OAuth response with a utility used for parsing HTTP requests, but hey, I guess if it works for them, fine.

For me though, I need to replace their use of parse_utf8_qsl(s) with json.loads(s.decode()) because my response is proper JSON - shouldn't OAuth responses be JSON anyway?

Whatever, it's late.

EDIT: Okay so it turns out I was doing silly things like not reading the OAuth spec and the response should be a query-string type thing like oauth_token=foo&oauth_token_secret=bar instead, which is what the library parses just fine by default. Reading specs is a good plan, one I encourage everyone to do.

My pull request is still valid though, if you really must break the spec, they have the parser argument already, and it should work in a more sensible way.

yet another bugfix

3:24pm on Apr 10, 2014

Another bugfix for s3cmd.

bugfixin

10:37am on Mar 25, 2014

Bugfix for s3cmd - some issues with command-line arguments not working when I needed them to.

RSS alert feed bot

5:28pm on Mar 11, 2014

Today I created a program to pull data from the RSS feeds our service vendors use for alerts, and either log, email, or instant message (we use Hipchat) to various support groups.

AND, I open sourced it on github. Enjoy!

rom

10:16pm on Feb 27, 2014

More python 3.3 porting, this time an interesting Redis ORM.

EDIT: Changed my mind, someone else has started a 3.3 port which looks like a way better method: mayfield/rom.

Google you little...

9:16pm on Oct 28, 2013

I see the Google plus article format returned by their Python API has changed again. You will note the sidebar over on the right there only shows images and no articles now. I'm getting really tired of fixing this every month.

Probably I'll just not bother soon, and remove that whole sidebar altogether.

whoa python iterators buffer

1:01pm on Jun 21, 2013

So I've been using this code in a few programs at work:

1
2
3
4
p = subprocess.Popen(...)
for line in p.stdout.readline():
   ...
   print(line)

It turns out there's a bunch of output buffering going on here. You could put a sys.stdout.flush() after that print, but it won't help.

The iterator buffers. Do this:

1
2
3
4
5
6
7
p = subprocess.Popen(...)
while True:
    line = p.stdout.readline()
    if not line:
        break
    ---
    print(line)

Et violà! No buffering.

Python 3 porting

12:08pm on Mar 07, 2013

Someone finally got me into the idea of using Python 3.x, so I started looking at my current projects, and picked one to test with. This resulted in me having to port a pretty major library, python-rrdtool. The trick about this is that RRDTool is a C library, so the Python module is an extension module, written in C.

And of course, strings and unicode are different from Python 2.x to 3.x....

Anyway, here's my pull request: on github

[RSS] [atom]
Tags