Re: [twitter-dev] Re: Frequent errors when using OAuth, none when using basic
However, if oauth-proxy is indeed doing OAuth as badly as your list of faults implies, I may have a bit of a job on my hands to figure out what it's doing and fix it, or might try to find some other OAuth proxy or client. Pity, though, as oauth-proxy was about the only thing I'd found so far which lets me send tweets relatively easily from a shell script. (There was a curl-alike with OAuth support whose name I forget, which had so many dependencies (Ruby, I think) that I eventually gave up trying to get it to work.) I'm in the middle of tidying up a python-based oauth command-line client that I've written[1], to improve debugging output and remove a dependency. Would that be at all helpful? I aim to finish the tidyup in the next couple of hours (as it's mostly just a case of committing code). The only dependencies will be PyYAML[2] and httplib2[3], although the current version also depends on python-oauth2[4] which, despite its name, is an OAuth 1.0a client. I also plan to generate a setup script that will automagically fetch and install the required dependencies. Dave [1] http://github.com/dingram/pycloc [2] http://pypi.python.org/pypi/PyYAML [3] http://pypi.python.org/pypi/httplib2 [4] http://github.com/simplegeo/python-oauth2
Re: [twitter-dev] Re: Frequent errors when using OAuth, none when using basic
However, if oauth-proxy is indeed doing OAuth as badly as your list of faults implies, I may have a bit of a job on my hands to figure out what it's doing and fix it, or might try to find some other OAuth proxy or client. Pity, though, as oauth-proxy was about the only thing I'd found so far which lets me send tweets relatively easily from a shell script. (There was a curl-alike with OAuth support whose name I forget, which had so many dependencies (Ruby, I think) that I eventually gave up trying to get it to work.) ITYM twurl I'm in the middle of tidying up a python-based oauth command-line client that I've written[1], to improve debugging output and remove a dependency. Would that be at all helpful? I aim to finish the tidyup in the next couple of hours (as it's mostly just a case of committing code). The only dependencies will be PyYAML[2] and httplib2[3], although the current version also depends on python-oauth2[4] which, despite its name, is an OAuth 1.0a client. I also plan to generate a setup script that will automagically fetch and install the required dependencies. [1] http://github.com/dingram/pycloc I'll also throw in a plug for TTYtter, which has no dependencies other than cURL itself (it includes its own OAuth code built-in) and is Perl. It has specific support for scripting (look at -status=... and -runcommand). http://www.floodgap.com/software/ttytter/ -- personal: http://www.cameronkaiser.com/ -- Cameron Kaiser * Floodgap Systems * www.floodgap.com * ckai...@floodgap.com -- Today's Internal Revenue Service: We got what it takes to take what you got!
[twitter-dev] Re: Frequent errors when using OAuth, none when using basic
On Aug 4, 3:54 pm, Cameron Kaiser spec...@floodgap.com wrote: ITYM twurl Could well have been. I seem to remember spending ages installing dependencies with gem install (few of them appeared to be available in Debian packages) and eventually ran into a brick wall where the versions required just didn't seem to be available from wherever gem install gets them from. Dave Ingram d...@dmi.me.uk wrote: I'm in the middle of tidying up a python-based oauth command-line client Cameron Kaiser again: I'll also throw in a plug for TTYtter, which has no dependencies other than Thanks for the suggestions, but actually I think I've managed to fix things without switching to something completely different. Main thing was, I'd either misread, or just failed to read, the documentation for curl's -d option. It needs to be URL-encoded before passing to curl. I am how stuffing the text I want to send through the following; probably overkill, but it seems to work: TWEET=$(echo -n $MSG | head -c140 | od -An -tx1 -v | tr '\n' ' ' | sed 's/^/ /;s/[^0-9A-Fa-f]/ /g;s/ *$//;s/ */%/g') Basically, it %-encodes every character. The other thing I fixed was oauth-proxy itself. Including the status= parameter in the Authorization header does seem to break things sometimes, probably depending on which special characters are included (and probably not properly escaped) in the value. This patch seems to fix that: --- oauth/oauth.py.orig 2010-08-04 20:06:55.0 +0100 +++ oauth/oauth.py2010-08-04 16:16:42.0 +0100 @@ -118,12 +118,22 @@ parameters[k] = v return parameters +# get only oauth parameters +def get_oauth_parameters(self): +parameters = {} +for k, v in self.parameters.iteritems(): +# ignore oauth parameters +if k.find('oauth_') == 0: +parameters[k] = v +return parameters + # serialize as a header for an HTTPAuth request def to_header(self, realm=''): auth_header = 'OAuth realm=%s' % realm # add the oauth parameters -if self.parameters: -for k, v in self.parameters.iteritems(): +parameters = self.get_oauth_parameters() +if parameters: +for k, v in parameters.iteritems(): auth_header += ', %s=%s' % (k, v) return {'Authorization': auth_header} With these two fixes, I haven't yet had any problems. Thanks for the help! --Charles
[twitter-dev] Re: Frequent errors when using OAuth, none when using basic
Hi Taylor, Thanks for your analysis. As mentioned, I'm using oauth-proxy (http:// github.com/mojodna/oauth-proxy, I think was the URL); I wrote none of the OAuth code, so I have no idea what it may or may not be doing. I tried it, it seemed to work (until these problems posting nagios notifications) so I used it. You mentioned % characters not being properly encoded - I did wonder whether the problem was %-related before, but tried some test tweets containing % characters and generally found that they posted properly. I had a bit of a brainwave while on the train today, though, and realised that if = signs are being mishandled (not sure why I overlooked = before!), that would fit the symptoms. And indeed, it does look like that might be the problem - I just tried substituting _ for = in a previously failed notification, and it posted fine. However, if oauth-proxy is indeed doing OAuth as badly as your list of faults implies, I may have a bit of a job on my hands to figure out what it's doing and fix it, or might try to find some other OAuth proxy or client. Pity, though, as oauth-proxy was about the only thing I'd found so far which lets me send tweets relatively easily from a shell script. (There was a curl-alike with OAuth support whose name I forget, which had so many dependencies (Ruby, I think) that I eventually gave up trying to get it to work.) It's also possible that I may be curling data into oauth-proxy incorrectly - I will try doing %-escaping on my argument to curl's -d option and see how that affects things. Anyway, for now, I can replace = with _. When I have time, I can either try staring hard at oauth-proxy to try to understand and fix it, or look for an alternative tool. Hmm, maybe by then, curl will have OAuth support... Thanks for your help, --Charles