To send a tweet with a picture - BrokenPipeError: [Errno 32] Broken pipe


#1

Hello everyone,
I’m in the process of creating a Python software procedure - my main purpose in to send a tweet with a picture. I’m using the library built for the twitter platform “Python Twitter Tools” (https://github.com/sixohsix/twitter)
If I run the application in a Unix machine (Centos) the system generates the following error message: BrokenPipeError: [Errno 32] Broken pipe
Instead if I decide to run the same application in a machine with windows operating system no message error appears and the operations succeeds.

Would anyone be able to tell me why?

Thanks a lot in advance.

Best wishes,
Alessandro

Source code:

try:
# Send a tweet with an image included (or set your banner or logo similarily)
# by just reading your image from the web or a file in a string:
with open(status, "rb") as imagefile:
    params = {"media[]": imagefile.read(), "status": "Test invio immagine..."}
outcome = t.statuses.update_with_media(**params)
...

Traceback (most recent call last):

File “/usr/local/lib/python3.3/urllib/request.py”, line 1248, in do_open
h.request(req.get_method(), req.selector, req.data, headers)
File “/usr/local/lib/python3.3/http/client.py”, line 1061, in request
self._send_request(method, url, body, headers)
File “/usr/local/lib/python3.3/http/client.py”, line 1099, in _send_request
self.endheaders(body)
File “/usr/local/lib/python3.3/http/client.py”, line 1057, in endheaders
self._send_output(message_body)
File “/usr/local/lib/python3.3/http/client.py”, line 902, in _send_output
self.send(msg)
File “/usr/local/lib/python3.3/http/client.py”, line 871, in send
self.sock.sendall(data)
File “/usr/local/lib/python3.3/ssl.py”, line 425, in sendall
v = self.send(data[count:])
File “/usr/local/lib/python3.3/ssl.py”, line 386, in send
v = self._sslobj.write(data)
BrokenPipeError: [Errno 32] Broken pipe

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File “/dstar/tmp/test2.py”, line 53, in
polling()
File “/dstar/tmp/test2.py”, line 49, in polling
send_to_twitter(“image.jpg”)
File “/dstar/tmp/test2.py”, line 31, in send_to_twitter
outcome = t.statuses.update_with_media(**params)
File “/usr/local/lib/python3.3/site-packages/twitter-1.10.0-py3.3.egg/twitter/api.py”, line 204, in call
return self._handle_response(req, uri, arg_data, _timeout)
File “/usr/local/lib/python3.3/site-packages/twitter-1.10.0-py3.3.egg/twitter/api.py”, line 211, in _handle_response
handle = urllib_request.urlopen(req, **kwargs)
File “/usr/local/lib/python3.3/urllib/request.py”, line 156, in urlopen
return opener.open(url, data, timeout)
File “/usr/local/lib/python3.3/urllib/request.py”, line 469, in open
response = self._open(req, data)
File “/usr/local/lib/python3.3/urllib/request.py”, line 487, in _open
’_open’, req)
File “/usr/local/lib/python3.3/urllib/request.py”, line 447, in _call_chain
result = func(*args)
File “/usr/local/lib/python3.3/urllib/request.py”, line 1283, in https_open
context=self._context, check_hostname=self._check_hostname)
File “/usr/local/lib/python3.3/urllib/request.py”, line 1251, in do_open
raise URLError(err)
urllib.error.URLError: urlopen error [Errno 32] Broken pipe>

Trace TCP/IP:

19:21:53.180764 IP 10.0.0.2.25232 > ns1.p34.dynect.net.domain: 30001 [1au] AAAA? api.twitter.com. (44)
19:21:53.225168 IP ns1.p34.dynect.net.domain > 10.0.0.2.25232: 30001*- 0/1/1 (116)
19:21:53.227612 IP 10.0.0.2.14642 > ns3.p34.dynect.net.domain: 32103 [1au] A? api.twitter.com. (44)
19:21:53.299637 IP ns3.p34.dynect.net.domain > 10.0.0.2.14642: 32103*- 4/4/1 A 199.16.156.40,[|domain]
19:21:53.305391 IP 10.0.0.2.52772 > 199.16.156.72.https: S 1062698777:1062698777(0) win 5840 <mss 1460,sackOK,timestamp 350447671 0,nop,wscale 7>
19:21:53.461770 IP 199.16.156.72.https > 10.0.0.2.52772: S 898493203:898493203(0) ack 1062698778 win 14480 <mss 1440,sackOK,timestamp 179084769 350447671,nop,wscale 8>
19:21:53.461802 IP 10.0.0.2.52772 > 199.16.156.72.https: . ack 1 win 46 <nop,nop,timestamp 350447827 179084769>
19:21:53.462067 IP 10.0.0.2.52772 > 199.16.156.72.https: P 1:73(72) ack 1 win 46 <nop,nop,timestamp 350447827 179084769>
19:21:53.593662 IP 199.16.156.72.https > 10.0.0.2.52772: . ack 73 win 57 <nop,nop,timestamp 179084900 350447827>
19:21:53.594277 IP 199.16.156.72.https > 10.0.0.2.52772: . 1:1401(1400) ack 73 win 57 <nop,nop,timestamp 179084900 350447827>
19:21:53.594773 IP 199.16.156.72.https > 10.0.0.2.52772: . 1401:2801(1400) ack 73 win 57 <nop,nop,timestamp 179084900 350447827>
19:21:53.595596 IP 199.16.156.72.https > 10.0.0.2.52772: P 2801:2936(135) ack 73 win 57 <nop,nop,timestamp 179084900 350447827>
19:21:53.596048 IP 10.0.0.2.52772 > 199.16.156.72.https: . ack 1401 win 69 <nop,nop,timestamp 350447961 179084900>
19:21:53.596056 IP 10.0.0.2.52772 > 199.16.156.72.https: . ack 2801 win 91 <nop,nop,timestamp 350447961 179084900>
19:21:53.596060 IP 10.0.0.2.52772 > 199.16.156.72.https: . ack 2936 win 113 <nop,nop,timestamp 350447961 179084900>
19:21:53.596757 IP 10.0.0.2.52772 > 199.16.156.72.https: P 73:399(326) ack 2936 win 113 <nop,nop,timestamp 350447962 179084900>

19:21:56.422471 IP 10.0.0.2.52772 > 199.16.156.72.https: P 106821:108249(1428) ack 2995 win 113 <nop,nop,timestamp 350450788 179087730>
19:21:56.422476 IP 10.0.0.2.52772 > 199.16.156.72.https: . 108249:109677(1428) ack 2995 win 113 <nop,nop,timestamp 350450788 179087730>
19:21:56.422754 IP 199.16.156.72.https > 10.0.0.2.52772: P 2995:3176(181) ack 99681 win 59 <nop,nop,timestamp 179087730 350450548>
19:21:56.423218 IP 199.16.156.72.https > 10.0.0.2.52772: P 3176:3213(37) ack 99681 win 61 <nop,nop,timestamp 179087730 350450548>
19:21:56.424783 IP 199.16.156.72.https > 10.0.0.2.52772: F 3213:3213(0) ack 99681 win 61 <nop,nop,timestamp 179087730 350450548>
19:21:56.430299 IP 199.16.156.72.https > 10.0.0.2.52772: R 898496198:898496198(0) win 0
19:21:56.441472 IP 199.16.156.72.https > 10.0.0.2.52772: R 898496198:898496198(0) win 0


#2

It looks like it could be an SSL issue, given the point in the code at which the error occurs. I can’t be sure though.

Have you tried raising the issue with the author of the library specifically? (ah yes, I can see you have!)


#3

Hello Andy,
First of all thank you very much for your reply, the only one I got so far.It appears to be a big challenge…
Would you give me a hand on that? Do you know anyone I could chat with to understand better what’s going on? Do you think this is a problem in the Unix environment? If we had a SSL issue, what do you think I can do about it?

Thanks again for all your support.

Best regards,
Alessandro


#4

I don’t have a CentOS machine handy to test this myself.

If it was me :wink: I would probably check the version of OpenSSL installed is up-to-date; check your hostname is set correctly and can be read from Python; check the timezone and time setting matches the correct time (and check whether this is the same on the Windows machine); and try making some basic requests to HTTPS endpoints on different sites from a simple Python script.

Those are some simple debugging steps that might help you get to the bottom of the issue.


#5

Another thing to check is that the file size doesn’t exceed the limit on the Twitter API, but I’m guessing you’re trying to post the exact same image from both Windows and CentOS (and I think your script is failing before you even get to this point, so it is far less likely to be an issue).


#6

Hello Andy,
Thank you so much for you feedback.
I followed your suggestions and these are the results I obtained:

  • O.S.: CentOS release 5.11 (Final)

  • Openssl: Package openssl-0.9.8e-31.el5_11.i686 already installed and latest version Nothing to do

  • the Python script:
    python
    import socket
    print(socket.gethostname()

    gives me the following result:
    ir0up.localdomain - Is it correct?

  • the “date” command gives me back the following result:
    mer nov 26 12:59:24 CET 2014 - The time is correct.

  • the Python script:

    import http.client

    c = http.client.HTTPSConnection(www.google.it)
    c.request(“GET”, “/”)
    response = c.getresponse()
    print(response.status, response.reason)
    data = response.read()
    print(data)

    gives me the following result:
    200 OK

Finally, I’d like to confirm you that the image I send is the same either for o.s. Windows or o.s. Centos.

Thanks once again for all your kind support!

Best regards,
Alessandro


#7

The hostname looks strange - what result do you get on Windows? That looks like a local domain, not an interface that is connected to the Internet.