As Damon suggested; get wireshark (formerly called ethereal) it is typically the best place to start when debugging weird network issues.<br><br>cheers,<br><br>S<br><br><div class="gmail_quote">On Wed, Mar 11, 2009 at 3:37 PM, Damon McCormick <span dir="ltr">&lt;<a href="mailto:damonmc@gmail.com">damonmc@gmail.com</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">I&#39;ve used a  tool called <a href="http://www.charlesproxy.com/" target="_blank">Charles</a> for http,  and <a href="http://www.wireshark.org/" target="_blank">Wireshark</a> is the standard for general protocol analysis.  Both run on OS X.<br>
<font color="#888888"><br>-Damon</font><div><div></div><div class="h5"><br>
<br><div class="gmail_quote">On Wed, Mar 11, 2009 at 3:14 PM, Daryl Spitzer <span dir="ltr">&lt;<a href="mailto:daryl.spitzer@gmail.com" target="_blank">daryl.spitzer@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">

Thanks Benjamin.  I should have wrote sooner to add that I&#39;ve<br>
confirmed that curl -u works.  So the problem is definitely with my<br>
Python basic HTTP authentication code.<br>
<br>
I also should have explained that I want to use urllib2 because (as<br>
Michael Foord wrote in<br>
<a href="http://www.voidspace.org.uk/python/articles/urllib2.shtml#proxies" target="_blank">http://www.voidspace.org.uk/python/articles/urllib2.shtml#proxies</a>),<br>
urllib2 will auto-detect proxy settings and use them; curl--as far as<br>
I know--doesn&#39;t auto-detect proxy settings.  (So my code using query<br>
string parameters works fine at work through a proxy server and at<br>
home.)<br>
<br>
Also, I&#39;d just like to learn why my code doesn&#39;t work!<br>
<br>
I guess I should take jj&#39;s advice and look at what is being sent over<br>
the wire.  (And compare that to what&#39;s going over the wire with curl.)<br>
 I&#39;ve never done that before.  Can anyone recommend a tool for that<br>
(preferably that works on Mac OS X)?<br>
<br>
--<br>
<font color="#888888">Daryl<br>
</font><div><div></div><div><br>
<br>
On Wed, Mar 11, 2009 at 2:07 PM, Benjamin Sergeant &lt;<a href="mailto:bsergean@gmail.com" target="_blank">bsergean@gmail.com</a>&gt; wrote:<br>
&gt; Warning: quick and dirty solution with no error checking using curl and a<br>
&gt; unix pipe.<br>
&gt;<br>
&gt; - Benjamin<br>
&gt;<br>
&gt; [bsergean@localhost bin]$ cat trim.py<br>
&gt; #!/usr/bin/env python<br>
&gt;<br>
&gt; import os, sys<br>
&gt; from getpass import getpass<br>
&gt; import xml.dom.minidom<br>
&gt;<br>
&gt; if len(sys.argv) != 2:<br>
&gt;     print &#39;Usage: trim.py &lt;url to shorten&gt;&#39;<br>
&gt;     sys.exit(0)<br>
&gt;<br>
&gt; user = raw_input(&#39;username: &#39;)<br>
&gt; passwd = getpass(&#39;password: &#39;)<br>
&gt;<br>
&gt; # See <a href="http://tr.im/api" target="_blank">http://tr.im/api</a><br>
&gt; url = &#39;<a href="http://api.tr.im/api/trim_url.xml?url=%s&amp;newtrim=yes" target="_blank">http://api.tr.im/api/trim_url.xml?url=%s&amp;newtrim=yes</a>&#39; % sys.argv[1]<br>
&gt;<br>
&gt; # Warning: --silent don&#39;t show error messages<br>
&gt; cmd  = &#39;curl --silent --basic -u %s:%s &#39; % (user, passwd)<br>
&gt; cmd += url<br>
&gt;<br>
&gt; fd = os.popen(cmd, &#39;r&#39;)<br>
&gt; response = fd.read()<br>
&gt; print response<br>
&gt; fd.close()<br>
&gt;<br>
&gt; Doc = xml.dom.minidom.parseString(response)<br>
&gt; N = Doc.getElementsByTagName(&quot;url&quot;)<br>
&gt; shortened_url = str((N[0].childNodes)[0].data)<br>
&gt;<br>
&gt; print &#39;shortened url:&#39;, shortened_url<br>
&gt;<br>
&gt;<br>
&gt; [bsergean@localhost bin]$ python trim.py<br>
&gt; Usage: trim.py &lt;url to shorten&gt;<br>
&gt; [bsergean@localhost bin]$ python trim.py<br>
&gt; <a href="http://www.reddit.com/r/programming/" target="_blank">http://www.reddit.com/r/programming/</a><br>
&gt; username: bsergean<br>
&gt; password:<br>
&gt; &lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;<br>
&gt; &lt;trim&gt;<br>
&gt;   &lt;status result=&quot;OK&quot; code=&quot;200&quot; message=&quot;<a href="http://tr.im" target="_blank">tr.im</a> URL Added.&quot;/&gt;<br>
&gt;   &lt;url&gt;<a href="http://tr.im/hglC" target="_blank">http://tr.im/hglC</a>&lt;/url&gt;<br>
&gt;   &lt;reference&gt;ZfCAq7qcyouYXwfR2WsuBR6v3V4q7L&lt;/reference&gt;<br>
&gt;   &lt;trimpath&gt;hglC&lt;/trimpath&gt;<br>
&gt; &lt;/trim&gt;<br>
&gt;<br>
&gt; shortened url: <a href="http://tr.im/hglC" target="_blank">http://tr.im/hglC</a><br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt; On Tue, Mar 10, 2009 at 11:51 PM, Shannon -jj Behrens &lt;<a href="mailto:jjinux@gmail.com" target="_blank">jjinux@gmail.com</a>&gt;<br>
&gt; wrote:<br>
&gt;&gt;<br>
&gt;&gt; It may help to look at what is being sent over the wire.<br>
&gt;&gt;<br>
&gt;&gt; -jj<br>
&gt;&gt;<br>
&gt;&gt; On Tue, Mar 10, 2009 at 8:26 AM, Daryl Spitzer &lt;<a href="mailto:daryl.spitzer@gmail.com" target="_blank">daryl.spitzer@gmail.com</a>&gt;<br>
&gt;&gt; wrote:<br>
&gt;&gt; &gt; I&#39;m playing around, trying to write some code to use the <a href="http://tr.im" target="_blank">http://tr.im</a><br>
&gt;&gt; &gt; APIs (<a href="http://tr.im/api/" target="_blank">http://tr.im/api/</a>) to shorten a URL.<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; After reading <a href="http://docs.python.org/library/urllib2.html" target="_blank">http://docs.python.org/library/urllib2.html</a>, I tried:<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt;    TRIM_API_URL = &#39;<a href="http://api.tr.im/api" target="_blank">http://api.tr.im/api</a>&#39;<br>
&gt;&gt; &gt;    auth_handler = urllib2.HTTPBasicAuthHandler()<br>
&gt;&gt; &gt;    auth_handler.add_password(realm=&#39;<a href="http://tr.im" target="_blank">tr.im</a>&#39;,<br>
&gt;&gt; &gt;                              uri=TRIM_API_URL,<br>
&gt;&gt; &gt;                              user=USERNAME,<br>
&gt;&gt; &gt;                              passwd=PASSWORD)<br>
&gt;&gt; &gt;    opener = urllib2.build_opener(auth_handler)<br>
&gt;&gt; &gt;    urllib2.install_opener(opener)<br>
&gt;&gt; &gt;    response = urllib2.urlopen(&#39;%s/trim_simple?url=%s&#39;<br>
&gt;&gt; &gt;                               % (TRIM_API_URL, url_to_trim))<br>
&gt;&gt; &gt;    url = response.read().strip()<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; response.code is 200 (I think it should be 202).  url is valid, but<br>
&gt;&gt; &gt; the basic HTTP authentication doesn&#39;t seem to have worked, because the<br>
&gt;&gt; &gt; shortened URL isn&#39;t in my list of URLs (at <a href="http://tr.im/?page=1" target="_blank">http://tr.im/?page=1</a>).<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; After reading<br>
&gt;&gt; &gt; <a href="http://www.voidspace.org.uk/python/articles/authentication.shtml#doing-it-properly" target="_blank">http://www.voidspace.org.uk/python/articles/authentication.shtml#doing-it-properly</a><br>
&gt;&gt; &gt; I also tried:<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt;    TRIM_API_URL = &#39;<a href="http://api.tr.im/api" target="_blank">api.tr.im/api</a>&#39;<br>
&gt;&gt; &gt;    password_mgr = urllib2.HTTPPasswordMgrWithDefaultRealm()<br>
&gt;&gt; &gt;    password_mgr.add_password(None, TRIM_API_URL, USERNAME, PASSWORD)<br>
&gt;&gt; &gt;    auth_handler = urllib2.HTTPBasicAuthHandler(password_mgr)<br>
&gt;&gt; &gt;    opener = urllib2.build_opener(auth_handler)<br>
&gt;&gt; &gt;    urllib2.install_opener(opener)<br>
&gt;&gt; &gt;    response = urllib2.urlopen(&#39;http://%s/trim_simple?url=%s&#39;<br>
&gt;&gt; &gt;                               % (TRIM_API_URL, url_to_trim))<br>
&gt;&gt; &gt;    url = response.read().strip()<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; But I get the same results.  (response.code is 200 and url is valid,<br>
&gt;&gt; &gt; but not recorded in my account at <a href="http://tr.im/" target="_blank">http://tr.im/</a>.)<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; If I use query string parameters instead of basic HTTP authentication,<br>
&gt;&gt; &gt; like this:<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt;    TRIM_API_URL = &#39;<a href="http://api.tr.im/api" target="_blank">http://api.tr.im/api</a>&#39;<br>
&gt;&gt; &gt;    response =<br>
&gt;&gt; &gt; urllib2.urlopen(&#39;%s/trim_simple?url=%s&amp;username=%s&amp;password=%s&#39;<br>
&gt;&gt; &gt;                               % (TRIM_API_URL,<br>
&gt;&gt; &gt;                                  url_to_trim,<br>
&gt;&gt; &gt;                                  USERNAME,<br>
&gt;&gt; &gt;                                  PASSWORD))<br>
&gt;&gt; &gt;    url = response.read().strip()<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; ...then not only is url valid but it&#39;s recorded in my <a href="http://tr.im" target="_blank">tr.im</a> account.<br>
&gt;&gt; &gt; (Though response.code is still 200.)<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; Either there must be something wrong in my authentication code, or in<br>
&gt;&gt; &gt; <a href="http://tr.im" target="_blank">tr.im</a>&#39;s.  (I&#39;ve written <a href="mailto:api@tr.im" target="_blank">api@tr.im</a> to see if it&#39;s a known problem and<br>
&gt;&gt; &gt; haven&#39;t received a response.)<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; Can anyone spot any problems?<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; --<br>
&gt;&gt; &gt; Daryl<br>
&gt;&gt; &gt; _______________________________________________<br>
&gt;&gt; &gt; Baypiggies mailing list<br>
&gt;&gt; &gt; <a href="mailto:Baypiggies@python.org" target="_blank">Baypiggies@python.org</a><br>
&gt;&gt; &gt; To change your subscription options or unsubscribe:<br>
&gt;&gt; &gt; <a href="http://mail.python.org/mailman/listinfo/baypiggies" target="_blank">http://mail.python.org/mailman/listinfo/baypiggies</a><br>
&gt;&gt; &gt;<br>
&gt;&gt;<br>
&gt;&gt;<br>
&gt;&gt;<br>
&gt;&gt; --<br>
&gt;&gt; In this life we cannot do great things. We can only do small things<br>
&gt;&gt; with great love. -- Mother Teresa<br>
&gt;&gt; <a href="http://jjinux.blogspot.com/" target="_blank">http://jjinux.blogspot.com/</a><br>
&gt;&gt; _______________________________________________<br>
&gt;&gt; Baypiggies mailing list<br>
&gt;&gt; <a href="mailto:Baypiggies@python.org" target="_blank">Baypiggies@python.org</a><br>
&gt;&gt; To change your subscription options or unsubscribe:<br>
&gt;&gt; <a href="http://mail.python.org/mailman/listinfo/baypiggies" target="_blank">http://mail.python.org/mailman/listinfo/baypiggies</a><br>
&gt;<br>
&gt;<br>
_______________________________________________<br>
Baypiggies mailing list<br>
<a href="mailto:Baypiggies@python.org" target="_blank">Baypiggies@python.org</a><br>
To change your subscription options or unsubscribe:<br>
<a href="http://mail.python.org/mailman/listinfo/baypiggies" target="_blank">http://mail.python.org/mailman/listinfo/baypiggies</a><br>
</div></div></blockquote></div><br>
</div></div><br>_______________________________________________<br>
Baypiggies mailing list<br>
<a href="mailto:Baypiggies@python.org">Baypiggies@python.org</a><br>
To change your subscription options or unsubscribe:<br>
<a href="http://mail.python.org/mailman/listinfo/baypiggies" target="_blank">http://mail.python.org/mailman/listinfo/baypiggies</a><br></blockquote></div><br><br clear="all"><br>-- <br>---<br>Failures are finger posts on the road to achievement. <br>
<br> -- C.S. Lewis<br>