shramik
Posts: 22
Joined: Sat Jan 07, 2017 11:31 am

facebook-sdk connection error

Sat Dec 09, 2017 6:54 am

i am using facebook-sdk to upload images. it works fine but when there is a poor connection i get an error.
so how can use try except exception to avoid this and keep the loop running.

Code: Select all

import facebook
access_token = " "
graph = facebook.GraphAPI(access_token)

graph.put_photo(image=open('1.jpg', 'rb'), message='xyz')
error:

Code: Select all

Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 516, in urlopen
    body=body, headers=headers)
  File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 308, in _make_request
    conn.request(method, url, **httplib_request_kw)
  File "/usr/lib/python3.4/http/client.py", line 1090, in request
    self._send_request(method, url, body, headers)
  File "/usr/lib/python3.4/http/client.py", line 1128, in _send_request
    self.endheaders(body)
  File "/usr/lib/python3.4/http/client.py", line 1086, in endheaders
    self._send_output(message_body)
  File "/usr/lib/python3.4/http/client.py", line 928, in _send_output
    self.send(message_body)
  File "/usr/lib/python3.4/http/client.py", line 890, in send
    self.sock.sendall(data)
  File "/usr/lib/python3.4/ssl.py", line 717, in sendall
    v = self.send(data[count:])
  File "/usr/lib/python3.4/ssl.py", line 678, in send
    v = self._sslobj.write(data)
ConnectionResetError: [Errno 104] Connection reset by peer

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/requests/adapters.py", line 362, in send
    timeout=timeout
  File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 559, in urlopen
    _pool=self, _stacktrace=stacktrace)
  File "/usr/lib/python3/dist-packages/urllib3/util/retry.py", line 245, in increment
    raise six.reraise(type(error), error, _stacktrace)
  File "/usr/lib/python3/dist-packages/six.py", line 624, in reraise
    raise value.with_traceback(tb)
  File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 516, in urlopen
    body=body, headers=headers)
  File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 308, in _make_request
    conn.request(method, url, **httplib_request_kw)
  File "/usr/lib/python3.4/http/client.py", line 1090, in request
    self._send_request(method, url, body, headers)
  File "/usr/lib/python3.4/http/client.py", line 1128, in _send_request
  File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 516, in urlopen
    body=body, headers=headers)
  File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 308, in _make_request
    conn.request(method, url, **httplib_request_kw)
  File "/usr/lib/python3.4/http/client.py", line 1090, in request
    self._send_request(method, url, body, headers)
  File "/usr/lib/python3.4/http/client.py", line 1128, in _send_request
    self.endheaders(body)
  File "/usr/lib/python3.4/http/client.py", line 1086, in endheaders
    self._send_output(message_body)
  File "/usr/lib/python3.4/http/client.py", line 928, in _send_output
    self.send(message_body)
  File "/usr/lib/python3.4/http/client.py", line 890, in send
    self.sock.sendall(data)
  File "/usr/lib/python3.4/ssl.py", line 717, in sendall
    v = self.send(data[count:])
  File "/usr/lib/python3.4/ssl.py", line 678, in send
    v = self._sslobj.write(data)
ConnectionResetError: [Errno 104] Connection reset by peer

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/requests/adapters.py", line 362, in send
    timeout=timeout
  File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 559, in urlopen
    _pool=self, _stacktrace=stacktrace)
  File "/usr/lib/python3/dist-packages/urllib3/util/retry.py", line 245, in increment
    raise six.reraise(type(error), error, _stacktrace)
  File "/usr/lib/python3/dist-packages/six.py", line 624, in reraise
    raise value.with_traceback(tb)
  File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 516, in urlopen
    body=body, headers=headers)
  File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 308, in _make_request
    conn.request(method, url, **httplib_request_kw)
  File "/usr/lib/python3.4/http/client.py", line 1090, in request
    self._send_request(method, url, body, headers)
  File "/usr/lib/python3.4/http/client.py", line 1128, in _send_request
    self._send_output(message_body)
  File "/usr/lib/python3.4/http/client.py", line 928, in _send_output
    self.send(message_body)
  File "/usr/lib/python3.4/http/client.py", line 890, in send
    self.sock.sendall(data)
  File "/usr/lib/python3.4/ssl.py", line 717, in sendall
    v = self.send(data[count:])
  File "/usr/lib/python3.4/ssl.py", line 678, in send
    v = self._sslobj.write(data)
urllib3.exceptions.ProtocolError: ('Connection aborted.', ConnectionResetError(104, 'Connection reset by peer'))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/pi/facebookimageupload.py", line 8, in <module>
    graph.put_photo(image=open('1.jpg', 'rb'), message='@sssmirrorphotobooth')
  File "/usr/local/lib/python3.4/dist-packages/facebook/__init__.py", line 193, in put_photo
    method="POST")
  File "/usr/local/lib/python3.4/dist-packages/facebook/__init__.py", line 247, in request
    files=files)
  File "/usr/lib/python3/dist-packages/requests/api.py", line 49, in request
    return session.request(method=method, url=url, **kwargs)
  File "/usr/lib/python3/dist-packages/requests/sessions.py", line 457, in request
    resp = self.send(prep, **send_kwargs)
  File "/usr/lib/python3/dist-packages/requests/sessions.py", line 569, in send
    r = adapter.send(request, **kwargs)
  File "/usr/lib/python3/dist-packages/requests/adapters.py", line 407, in send
    raise ConnectionError(err, request=request)
requests.exceptions.ConnectionError: ('Connection aborted.', ConnectionResetError(104, 'Connection reset by peer'))

User avatar
DougieLawson
Posts: 32995
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website

Re: facebook-sdk connection error

Sat Dec 09, 2017 7:22 am

"Connection reset by peer" means the other end didn't like your credentials so it killed your TCP/IP connection.
Microprocessor, Raspberry Pi & Arduino Hacker
Mainframe database troubleshooter
MQTT Evangelist
Twitter: @DougieLawson

2012-18: 1B*5, 2B*2, B+, A+, Z, ZW, 3Bs*3, 3B+

Any DMs sent on Twitter will be answered next month.

shramik
Posts: 22
Joined: Sat Jan 07, 2017 11:31 am

Re: facebook-sdk connection error

Sat Dec 09, 2017 8:02 am

but when i have a good connection i can upload but at poor connection i get this error
so is there a way to bypass this error when it occur?

User avatar
DougieLawson
Posts: 32995
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website

Re: facebook-sdk connection error

Sat Dec 09, 2017 8:08 am

You'll have to ask on a Facebook developer forum.

I gave up FB in 2013 and haven't regretted it for a single day.
Microprocessor, Raspberry Pi & Arduino Hacker
Mainframe database troubleshooter
MQTT Evangelist
Twitter: @DougieLawson

2012-18: 1B*5, 2B*2, B+, A+, Z, ZW, 3Bs*3, 3B+

Any DMs sent on Twitter will be answered next month.

Return to “Python”

Who is online

Users browsing this forum: No registered users and 11 guests