1

We are working on a mobile app where we are using firebase, we are using firestore as our database and maintaining data in collections here the thing we have to post the data to salesforce whenever there is any change or update in any of the records in order to do this we have created firestore triggers in the cloud using python 3.7 using this reference Click Here , the cloud function is Trigger type as Cloud Firestore (Beta) and Event type as providers/cloud.firestore/eventTypes/document.write using {wildcard} with the path as Shipments/{ShipmentId} and it is triggered whenever there is a change in Shipments Collections modified my code in main.py file as

import requests

def TriggerShipmentChange(event, context):
    resource_string = context.resource
    print("function trigger by change to",{resource_string})
    data = event
    if data["oldValue"] == {} and data["updateMask"] == {}:        
        print("New shipment record $$$ Created $$$", data["value"])
    elif data["updateMask"] == {} and data["value"] == {}:
        print("Shipment record is $$$ deleted $$$", data["oldValue"])
    elif data["oldValue"] != {} and data["value"] != {} and  data["updateMask"] != {}:
        print("Shipment record is $$$ updated $$$  and updated fields", data["updateMask"]["fieldPaths"])
        print("updated values", data["value"])
    else:
        print("Function Response", data)

    print("update details in backend")
    URL ='http://*****.herokuapp.com'
    result = requests.get(URL)
    print("response", result.status_code, result.content)

and updated requirements.txt with

requests==2.22.0

and changed Function to execute to TriggerShipmentChange

I am able to execute these triggers and get the data of the updated record and hence planning to post them to salesforce here am using an external service to post data but first, in order to check connection I just made a get request which is throwing an error. Here I need to make a post request to an external server which is hosted in Heroku. I'll attach my logs

Function execution took 101 ms, finished with status: 'crash'

 Traceback (most recent call last):
  File "/env/local/lib/python3.7/site-packages/urllib3/connection.py", line 157, in _new_conn
    (self._dns_host, self.port), self.timeout, **extra_kw
  File "/env/local/lib/python3.7/site-packages/urllib3/util/connection.py", line 61, in create_connection
    for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM):
  File "/opt/python3.7/lib/python3.7/socket.py", line 748, in getaddrinfo
    for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
socket.gaierror: [Errno -3] Temporary failure in name resolution

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/env/local/lib/python3.7/site-packages/urllib3/connectionpool.py", line 672, in urlopen
    chunked=chunked,
  File "/env/local/lib/python3.7/site-packages/urllib3/connectionpool.py", line 387, in _make_request
    conn.request(method, url, **httplib_request_kw)
  File "/opt/python3.7/lib/python3.7/http/client.py", line 1244, in request
    self._send_request(method, url, body, headers, encode_chunked)
  File "/opt/python3.7/lib/python3.7/http/client.py", line 1290, in _send_request
    self.endheaders(body, encode_chunked=encode_chunked)
  File "/opt/python3.7/lib/python3.7/http/client.py", line 1239, in endheaders
    self._send_output(message_body, encode_chunked=encode_chunked)
  File "/opt/python3.7/lib/python3.7/http/client.py", line 1026, in _send_output
    self.send(msg)
  File "/opt/python3.7/lib/python3.7/http/client.py", line 966, in send
    self.connect()
  File "/env/local/lib/python3.7/site-packages/urllib3/connection.py", line 184, in connect
    conn = self._new_conn()
  File "/env/local/lib/python3.7/site-packages/urllib3/connection.py", line 169, in _new_conn
    self, "Failed to establish a new connection: %s" % e
urllib3.exceptions.NewConnectionError: <urllib3.connection.HTTPConnection object at 0x7eef49645410>: Failed to establish a new connection: [Errno -3] Temporary failure in name resolution

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/env/local/lib/python3.7/site-packages/requests/adapters.py", line 449, in send
    timeout=timeout
  File "/env/local/lib/python3.7/site-packages/urllib3/connectionpool.py", line 720, in urlopen
    method, url, error=e, _pool=self, _stacktrace=sys.exc_info()[2]
  File "/env/local/lib/python3.7/site-packages/urllib3/util/retry.py", line 436, in increment
    raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='nltmsfirst.herokuapp.com', port=80): Max retries exceeded with url: / (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7eef49645410>: Failed to establish a new connection: [Errno -3] Temporary failure in name resolution'))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/env/local/lib/python3.7/site-packages/google/cloud/functions/worker.py", line 383, in run_background_function
    _function_handler.invoke_user_function(event_object)
  File "/env/local/lib/python3.7/site-packages/google/cloud/functions/worker.py", line 217, in invoke_user_function
    return call_user_function(request_or_event)
  File "/env/local/lib/python3.7/site-packages/google/cloud/functions/worker.py", line 214, in call_user_function
    event_context.Context(**request_or_event.context))
  File "/user_code/main.py", line 35, in TriggerShipmentChange
    result = requests.get(URL)
  File "/env/local/lib/python3.7/site-packages/requests/api.py", line 75, in get
    return request('get', url, params=params, **kwargs)
  File "/env/local/lib/python3.7/site-packages/requests/api.py", line 60, in request
    return session.request(method=method, url=url, **kwargs)
  File "/env/local/lib/python3.7/site-packages/requests/sessions.py", line 533, in request
    resp = self.send(prep, **send_kwargs)
  File "/env/local/lib/python3.7/site-packages/requests/sessions.py", line 646, in send
    r = adapter.send(request, **kwargs)
  File "/env/local/lib/python3.7/site-packages/requests/adapters.py", line 516, in send
    raise ConnectionError(e, request=request)
requests.exceptions.ConnectionError: HTTPConnectionPool(host='nltmsfirst.herokuapp.com', port=80): Max retries exceeded with url: / (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7eef49645410>: Failed to establish a new connection: [Errno -3] Temporary failure in name resolution'))
 E  
updated values {'createTime': '2020-01-28T09:56:01.307748Z', 'fields': {'ShipmentId': {'stringValue': '1234'}, 'Status': {'stringValue': 'Tendered'}}, 'name': 'projects/tablet-app-b9154/databases/(default)/documents/App/Dnow/Shipments/SR#1234', 'updateTime': '2020-01-29T08:24:48.233535Z'}

Shipment record is $$$ updated $$$  and updated fields ['Status'] 

function trigger by change to {'projects/tablet-app-b9154/databases/(default)/documents/App/Dnow/Shipments/SR#1234'} 

Function execution started D  

I don't want to create a new HTTP function now, I just want to make the above code work is there any way to do that, if not how can I update this updated record data to another server?

Meghana Goud
  • 111
  • 1
  • 9
  • This has nothing to do with firestore, and everything to do with the API your are trying to request. So it could be something that has to do with DNS, maybe the endpoint is not online yet. Did you manage to figure it out? You could also just type the url in your browser, since it is similar to the get request you are trying to do. – Cloudkollektiv Feb 13 '20 at 16:11

0 Answers0