- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在 Jupyter notebook 上运行代码,我修改了这个 link 中的代码所以它从 Jupyter 笔记本而不是控制台获取它并迭代文件列表。
"""Demonstrates how to make a simple call to the Natural Language API."""
import argparse
import requests
from google.cloud import language
from google.cloud.language import enums
from google.cloud.language import types
def print_result(annotations, movie_review_filename):
score = annotations.document_sentiment.score
magnitude = annotations.document_sentiment.magnitude
file_path_split = movie_review_filename.split("/")
fileName = file_path_split[len(file_path_split) - 1][:-4]
sentencelist = []
statuslist = []
for index, sentence in enumerate(annotations.sentences):
sentence_sentiment = sentence.sentiment.score
singlesentence = [fileName, sentence.text.content, sentence.sentiment.magnitude, sentence_sentiment]
sentencelist.append(singlesentence)
outputdf = pd.DataFrame(sentencelist, columns = ['status_id', 'sentence', 'sentence_magnitude', 'sentence_sentiment'])
outputdf.to_csv("/Users/abhi/Desktop/RetrySentenceCSVs/" + fileName + ".csv", index = False)
return 0
def analyze(movie_review_filename):
"""Run a sentiment analysis request on text within a passed filename."""
client = language.LanguageServiceClient()
with open(movie_review_filename, 'r') as review_file:
# Instantiates a plain text document.
content = review_file.read()
document = types.Document(
content=content,
type=enums.Document.Type.PLAIN_TEXT)
annotations = client.analyze_sentiment(document=document)
# Print the results
print_result(annotations, movie_review_filename)
if __name__ == '__main__':
import glob
csv_file_list = glob.glob("/Users/abhi/Desktop/mytxtfilepath/*.txt")
for file in csv_file_list: #Iterate through a list of file paths
analyze(file)
ERROR:root:AuthMetadataPluginCallback "<google.auth.transport.grpc.AuthMetadataPlugin object at 0x113b76588>" raised exception!
Traceback (most recent call last):
File "/anaconda3/lib/python3.6/site-packages/urllib3/connection.py", line 171, in _new_conn
(self._dns_host, self.port), self.timeout, **extra_kw)
File "/anaconda3/lib/python3.6/site-packages/urllib3/util/connection.py", line 56, in create_connection
for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM):
File "/anaconda3/lib/python3.6/socket.py", line 745, in getaddrinfo
for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
socket.gaierror: [Errno 8] nodename nor servname provided, or not known
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/anaconda3/lib/python3.6/site-packages/urllib3/connectionpool.py", line 600, in urlopen
chunked=chunked)
File "/anaconda3/lib/python3.6/site-packages/urllib3/connectionpool.py", line 343, in _make_request
self._validate_conn(conn)
File "/anaconda3/lib/python3.6/site-packages/urllib3/connectionpool.py", line 849, in _validate_conn
conn.connect()
File "/anaconda3/lib/python3.6/site-packages/urllib3/connection.py", line 314, in connect
conn = self._new_conn()
File "/anaconda3/lib/python3.6/site-packages/urllib3/connection.py", line 180, in _new_conn
self, "Failed to establish a new connection: %s" % e)
urllib3.exceptions.NewConnectionError: <urllib3.connection.VerifiedHTTPSConnection object at 0x113b840b8>: Failed to establish a new connection: [Errno 8] nodename nor servname provided, or not known
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/anaconda3/lib/python3.6/site-packages/requests/adapters.py", line 445, in send
timeout=timeout
File "/anaconda3/lib/python3.6/site-packages/urllib3/connectionpool.py", line 638, in urlopen
_stacktrace=sys.exc_info()[2])
File "/anaconda3/lib/python3.6/site-packages/urllib3/util/retry.py", line 398, in increment
raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='accounts.google.com', port=443): Max retries exceeded with url: /o/oauth2/token (Caused by NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x113b840b8>: Failed to establish a new connection: [Errno 8] nodename nor servname provided, or not known',))
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/anaconda3/lib/python3.6/site-packages/google/auth/transport/requests.py", line 120, in __call__
**kwargs)
File "/anaconda3/lib/python3.6/site-packages/requests/sessions.py", line 512, in request
resp = self.send(prep, **send_kwargs)
File "/anaconda3/lib/python3.6/site-packages/requests/sessions.py", line 622, in send
r = adapter.send(request, **kwargs)
File "/anaconda3/lib/python3.6/site-packages/requests/adapters.py", line 513, in send
raise ConnectionError(e, request=request)
requests.exceptions.ConnectionError: HTTPSConnectionPool(host='accounts.google.com', port=443): Max retries exceeded with url: /o/oauth2/token (Caused by NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x113b840b8>: Failed to establish a new connection: [Errno 8] nodename nor servname provided, or not known',))
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/anaconda3/lib/python3.6/site-packages/grpc/_plugin_wrapping.py", line 77, in __call__
callback_state, callback))
File "/anaconda3/lib/python3.6/site-packages/google/auth/transport/grpc.py", line 77, in __call__
callback(self._get_authorization_headers(context), None)
File "/anaconda3/lib/python3.6/site-packages/google/auth/transport/grpc.py", line 65, in _get_authorization_headers
headers)
File "/anaconda3/lib/python3.6/site-packages/google/auth/credentials.py", line 122, in before_request
self.refresh(request)
File "/anaconda3/lib/python3.6/site-packages/google/oauth2/service_account.py", line 322, in refresh
request, self._token_uri, assertion)
File "/anaconda3/lib/python3.6/site-packages/google/oauth2/_client.py", line 145, in jwt_grant
response_data = _token_endpoint_request(request, token_uri, body)
File "/anaconda3/lib/python3.6/site-packages/google/oauth2/_client.py", line 106, in _token_endpoint_request
method='POST', url=token_uri, headers=headers, body=body)
File "/anaconda3/lib/python3.6/site-packages/google/auth/transport/requests.py", line 124, in __call__
six.raise_from(new_exc, caught_exc)
File "<string>", line 3, in raise_from
google.auth.exceptions.TransportError: HTTPSConnectionPool(host='accounts.google.com', port=443): Max retries exceeded with url: /o/oauth2/token (Caused by NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x113b840b8>: Failed to establish a new connection: [Errno 8] nodename nor servname provided, or not known',))
ERROR:root:AuthMetadataPluginCallback "<google.auth.transport.grpc.AuthMetadataPlugin object at 0x113b76588>" raised exception!
Traceback (most recent call last):
File "/anaconda3/lib/python3.6/site-packages/urllib3/connection.py", line 171, in _new_conn
(self._dns_host, self.port), self.timeout, **extra_kw)
File "/anaconda3/lib/python3.6/site-packages/urllib3/util/connection.py", line 56, in create_connection
for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM):
File "/anaconda3/lib/python3.6/socket.py", line 745, in getaddrinfo
for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
socket.gaierror: [Errno 8] nodename nor servname provided, or not known
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/anaconda3/lib/python3.6/site-packages/urllib3/connectionpool.py", line 600, in urlopen
chunked=chunked)
File "/anaconda3/lib/python3.6/site-packages/urllib3/connectionpool.py", line 343, in _make_request
self._validate_conn(conn)
File "/anaconda3/lib/python3.6/site-packages/urllib3/connectionpool.py", line 849, in _validate_conn
conn.connect()
File "/anaconda3/lib/python3.6/site-packages/urllib3/connection.py", line 314, in connect
conn = self._new_conn()
File "/anaconda3/lib/python3.6/site-packages/urllib3/connection.py", line 180, in _new_conn
self, "Failed to establish a new connection: %s" % e)
urllib3.exceptions.NewConnectionError: <urllib3.connection.VerifiedHTTPSConnection object at 0x113b84470>: Failed to establish a new connection: [Errno 8] nodename nor servname provided, or not known
During handling of the above exception, another exception occurred:
...
RendezVous
停止。错误(忘记捕获此消息)我想知道的是,代码如何为某些文件集工作一段时间并抛出错误消息,工作多一点,抛出错误消息,然后在一段时间后完全停止工作观点?
.txt
包含文字的文件。
sleep(10)
这似乎可以正常工作一段时间,但再次开始抛出错误..
最佳答案
我想到了。您将不必一次读取所有 600 个文件,而是尝试分批读取 50 个文件。 (创建 12 个文件夹,每个文件夹包含 50 个文件),并在每次扫描完文件夹时手动运行代码。我不确定为什么这似乎可行,但它确实有效。
关于python-3.x - Cloud Natural Language API 返回 socket.gaierror : nodename nor servname provided after performing Sentiment Analysis every now and then,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51775484/
我正在使用 Vagrant 运行 Centos 虚拟机。机器似乎运行正常,但是当我尝试同步 Perforce 时,我可以看到以下错误: [vagrant@vagrant-c5-x86_64 ~]$ /
我无法通过 paramiko 连接到其他服务器: import paramiko import sys import os hostname = 'server1' port = 22 usernam
所以,在我得到这个错误之后,我一直在这里寻找答案,几乎每个人都有一个很难解决这个错误的方法,但是没有人解释为什么会发生这个错误,所以我不认为这个问题是完全重复。 我用 C 语言编写了一个 TCP 套接
我正在尝试用 C 编写套接字程序。当我这样做时,我的整个代码都可以正常工作 #define PORT "3333" 但不是 #define PORT getParameter("setting.ini
我的 laradock 项目遇到了麻烦:我已经下载并安装了 docker,并且我已经使用 laradock 成功完成了我的 laravel 项目的设置。我使用 php 7、laravel(5.5.14
我基本上为 FOG 设置了以下 right out of the FOG website : def fog_save_file_for(filename, file) # create a co
我正在尝试使用带有路径样式 url 的 s3cmd 从我的 S3 存储桶访问对象。这个用Java SDK之类的是没有问题的。 s3Client.setS3ClientOptions(S3ClientO
当我尝试使用 MAMP 连接到 mac 上的主机时出现此错误 php_network_getaddresses: getaddrinfo failed: nodename nor servname p
我被一个看似与 asyncio + aiohttp 相关的问题难住了,当发送大量并发 GET 请求时,超过 85% 的请求会引发 aiohttp.client_exceptions.ClientCon
我尝试执行 git pull --rebase 但我收到以下错误: ssh: Could not resolve hostname git: nodename nor servname provide
我在运行 Mac OS X 10.6 的计算机上部署了一个 Ruby on Rails 应用程序。出现问题的代码是由delayed_job运行的。只有在通过 delayed_job 运行时才会出现此问
有人可以帮忙吗?? 我在连接时收到此错误.. abort: error: nodename nor servname provided, or not known 请帮帮我。 实际上我想从存储库中获取
我正在遵循这个关于本地安装 Mesos 的简单指南 https://mesosphere.com/2014/07/07/installing-mesos-on-your-mac-with-homebr
我正在尝试在 Docker 上设置 Symfony4 项目,除了 Doctrine CLI 功能之外,一切正常。当我通过 CLI 运行命令时,它似乎无法连接到数据库。 phpMyAdmin 和项目本身
我正在尝试通过 Python 脚本通过 SSH 连接到服务器。目前我正在试用 paramiko。我在客户端和服务器之间设置了一个公钥,所以我不需要密码。我目前正在使用以下代码: ssh = param
我正在尝试通过本教程学习如何使用套接字: https://www.tutorialspoint.com/python/python_networking.htm 我已将网站上的代码复制到我的目录中,并
我是 Hadoop 新手。我使用这个 link 在我的 MAC 上安装了 Hadoop 一开始它对我来说就像一个魅力,但现在当我从 Eclipse 运行相同的 WordCount 问题时遇到了这个问题
我观察到,这是因为端口。端口是 C++ 字符串。当我硬编码端口号时说“4091”我没有看到这个问题。有什么建议吗? int sockfd; struct addrinfo hints, *servin
我间歇性地收到此错误,但当它发生时,我使用 Django 的 LiveServerTestCase 进行的自动集成测试突然停止并抛出以下错误: WSGIServerException: [Errno
我正在尝试编写一个 go http 服务器,但是当我尝试收听传入连接时遇到问题。 硬件设置:MacOS Sierra 10.12.4,docker 17.03 我有一个 yml 文件可以打开一个 .
我是一名优秀的程序员,十分优秀!