title: google cloud function python CORS error No 'Access-Control-Allow-Origin' header is present on the requested resource.
body: <p>Ive followed instructions at <a href="https://cloud.google.com/functions/docs/writing/http#functions_http_cors-python" rel="nofollow noreferrer">https://cloud.google.com/functions/docs/writing/http#functions_http_cors-python</a> </p>
  
  <p>So my code has this at the end </p>
  
  <pre><code> # Set CORS headers for the preflight request
          if request.method == 'OPTIONS':
              # Allows GET requests from any origin with the Content-Type
              # header and caches preflight response for an 3600s
              headers = {
                  'Access-Control-Allow-Origin': '*',
                  'Access-Control-Allow-Methods': 'GET',
                  'Access-Control-Allow-Headers': 'Content-Type',
                  'Access-Control-Max-Age': '3600'
              }
  
              return ('', 204, headers)
  
          # Set CORS headers for the main request
          headers = {
              'Content-Type':'application/json',
              'Access-Control-Allow-Origin': '*',
              'Access-Control-Allow-Headers': 'Content-Type',
          }
  
          # END CORS
  
          return (res, 200, headers)
  </code></pre>
  
  <p>where res is JSON </p>
  
  <p>from a simple node app, im calling via</p>
  
  <pre><code>this.http.post(payloadTarget.url, JSON.stringify(clone)).subscribe(res =&gt; {
      console.log('request complete', res);
    },
    err =&gt; {
      console.log('request failed', err);
    });
  </code></pre>
  
  <p>im getting this error on console </p>
  
  <blockquote>
    <p>No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin '<a href="http://localhost:4200" rel="nofollow noreferrer">http://localhost:4200</a>' is therefore not allowed access.</p>
  </blockquote>
  
  <p>when testing a POST or OPTIONS using Postman i dont see the error but i also dont see the HEADERS im supposed to </p>
  
  <p>im sure its something simple but looking at others similar questions and answers cant find anything that points to my issue</p>