Node.js:提出请求时证书链中的自签名证书错误

时间:2018-07-27 00:10:47

标签: npm request self-signed

从请求中记录错误时,收到此错误:

{ Error: self signed certificate in certificate chain
    at TLSSocket.<anonymous> (_tls_wrap.js:1105:38)
    at emitNone (events.js:106:13)
    at TLSSocket.emit (events.js:208:7)
    at TLSSocket._finishInit (_tls_wrap.js:639:8)
    at TLSWrap.ssl.onhandshakedone (_tls_wrap.js:469:38) code: 'SELF_SIGNED_CERT_IN_CHAIN' }
Unable to connect to Google servers.

以下请求代码:

const request = require('request');

var geocodeAddress = (address, callback) => {
var encodedAddress = encodeURIComponent(address);

request({
url: `https://maps.googleapis.com/maps/api/geocode/json? 
address=${encodedAddress}`,
json: true
}, (error, response, body) => {
if (error) {
  callback('Unable to connect to Google servers.');
} else if (body.status === 'ZERO_RESULTS') {
  callback('Unable to find that address.');
} else if (body.status === 'OK') {
  callback(undefined, {
    address: body.results[0].formatted_address,
    latitude: body.results[0].geometry.location.lat,
    longitude: body.results[0].geometry.location.lng
  });
 }
 });
 };

module.exports.geocodeAddress = geocodeAddress;

当我尝试更新npm时,它说:

npm WARN registry Unexpected warning for https://registry.npmjs.org/: Miscellaneous Warning SELF_SIGNED_CERT_IN_CHAIN: request to https://registry.npmjs.org/npm failed, reason: self signed certificate in certificate chain

以及一组警告,指出检查写访问权限。

以下的错误
npm ERR! path /usr/local/lib/node_modules/npm/node_modules/cacache/node_modules/ssri
npm ERR! code EACCES
npm ERR! errno -13
npm ERR! syscall access
npm ERR! Error: EACCES: permission denied, access '/usr/local/lib/node_modules/npm/node_modules/cacache/node_modules/ssri'
npm ERR!  { Error: EACCES: permission denied, access '/usr/local/lib/node_modules/npm/node_modules/cacache/node_modules/ssri'
npm ERR!   stack: 'Error: EACCES: permission denied, access \'/usr/local/lib/node_modules/npm/node_modules/cacache/node_modules/ssri\'',
npm ERR!   errno: -13,
npm ERR!   code: 'EACCES',
npm ERR!   syscall: 'access',
npm ERR!   path: '/usr/local/lib/node_modules/npm/node_modules/cacache/node_modules/ssri' }
npm ERR! 
npm ERR! Please try running this command again as root/Administrator.

感谢您对为什么缺少写访问权限的解决方案和解释。我以前从未使用请求遇到此问题。 谢谢

0 个答案:

没有答案