0

I'm working on a project using Python(3.6) and Django(2) in which I need to process too many files from a directory by using Google cloud natural language processing API, but after processing ~100 files it returns an error as:

ssl.SSLEOFError: EOF occurred in violation of protocol (_ssl.c:852) [29/Dec/2018 13:27:33] "POST / HTTP/1.1" 500 17751

Here's from views.py:

def nlp_text_manager(text_path, name):
    text = text_path
    # encoding = predict_encoding(text_path)
    # print('encoding is: {}'.format(encoding))
    txt = Path(text_path).read_text(encoding='utf8')
    service = discovery.build('language', 'v1beta2', credentials=credentials)
    service_request = service.documents().analyzeSentiment(
        body={
            'document': {
                'type': 'PLAIN_TEXT',
                'content': txt
            }
        }
    )
    response = service_request.execute()
    return response
Abdul Rehman
  • 5,326
  • 9
  • 77
  • 150
  • Have you tried passing a non-zero `num_retries` argument to `execute()` to see if it can recover with retry? http://googleapis.github.io/google-api-python-client/docs/epy/googleapiclient.http.HttpRequest-class.html#execute – cody Dec 29 '18 at 14:43
  • Give it a try with `num_retries=5`, now it gives `OSError: [Errno 9] Bad file descriptor` after 5th file. – Abdul Rehman Dec 29 '18 at 14:51

0 Answers0