How to use the urllib.request function in urllib

To help you get started, we’ve selected a few urllib examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github qiniu / nodejs-sdk / qiniu / rpc.js View on Github external
data.agent = conf.RPC_HTTP_AGENT;
    }

    if (conf.RPC_HTTPS_AGENT) {
        data.httpsAgent = conf.RPC_HTTPS_AGENT;
    }

    if (Buffer.isBuffer(requestForm) || typeof requestForm === 'string') {
        data.content = requestForm;
    } else if (requestForm) {
        data.stream = requestForm;
    } else {
        data.headers['Content-Length'] = 0;
    }

    var req = urllib.request(requestURI, data, function (respErr, respBody,
        respInfo) {
    // var end = parseInt(Date.now() / 1000);
    // console.log((end - start) + " seconds");
    // console.log("queuing:\t" + respInfo.timing.queuing);
    // console.log("dnslookup:\t" + respInfo.timing.dnslookup);
    // console.log("connected:\t" + respInfo.timing.connected);
    // console.log("requestSent:\t" + respInfo.timing.requestSent);
    // console.log("waiting:\t" + respInfo.timing.waiting);
    // console.log("contentDownload:\t" + respInfo.timing.contentDownload);

        callbackFunc(respErr, respBody, respInfo);
    });

    return req;
}
github cnpm / mirrors / sync / PuppeteerChromeSyncer.js View on Github external
// const downloadURLs = {
  //   linux: '%s/chromium-browser-snapshots/Linux_x64/%d/%s.zip',
  //   mac: '%s/chromium-browser-snapshots/Mac/%d/%s.zip',
  //   win32: '%s/chromium-browser-snapshots/Win/%d/%s.zip',
  //   win64: '%s/chromium-browser-snapshots/Win_x64/%d/%s.zip',
  // };

  let existsCount = 0;
  const existDirResults = yield parentDirs.map(name => this.listExists('/' + name + '/'));
  const existDirsMap = {};
  for (const rows of existDirResults) {
    for (const row of rows) {
      existDirsMap[row.parent + row.name] = true;
    }
  }
  const result = yield urllib.request(this._npmPackageUrl, {
    timeout: 60000,
    dataType: 'json',
    gzip: true,
    followRedirect: true,
  });
  const versions = result.data.versions || {};
  const chromium_revisions = {};
  for (var version in versions) {
    const pkg = versions[version];
    const puppeteerInfo = pkg.puppeteer || {};
    if (!puppeteerInfo.chromium_revision) continue;
    if (chromium_revisions[puppeteerInfo.chromium_revision]) continue;

    const publish_time = result.data.time[pkg.version];
    chromium_revisions[puppeteerInfo.chromium_revision] = publish_time;
  }
github popomore / connect-combo / lib / file.js View on Github external
File.prototype.request = function(url, cb) {
  var that = this;
  var opt = {
    gzip: true,
    followRedirect: false,
    rejectUnauthorized: false,
  };
  request(url, opt, function(err, data, res) {
    if (err) {
      that.emit('not found', url);
      return cb(err);
    }

    if (res.statusCode >= 300) {
      that.emit('not found', url);
      return cb(new Error(res.statusCode));
    }

    that.emit('found', url);
    cb(null, {
      headers: shouldGetHeader(that.options) ? getOriginalHeader(res.headers) : null,
      data: data,
    });
  });
github node-webot / wechat / lib / api_shop_group.js View on Github external
exports._deleteGoodsGroup = function (groupId, callback) {
  var data = {
    "group_id": groupId
  };
  var url = this.merchantPrefix + 'group/del?access_token=' + this.token.accessToken;
  urllib.request(url, postJSON(data), wrapper(callback));
};
github kyfxbl / wechat-toolkit / lib / oauth2.js View on Github external
function exchangeAccessToken(app_id, app_secret, code, callback){

    var url = "https://api.weixin.qq.com/sns/oauth2/access_token?appid=" + app_id + "&secret=" + app_secret + "&code=" + code + "&grant_type=authorization_code";

    var opts = {
        dataType: 'json',
        type: 'GET'
    };

    urllib.request(url, opts, function(err, body, resp){

        if(err){
            callback(err);
            return;
        }

        if(body.errcode){
            callback(body);
            return;
        }

        callback(null, body);
    });
}
github kyfxbl / wechat-toolkit / lib / group.js View on Github external
var url = "https://api.weixin.qq.com/cgi-bin/groups/members/update?access_token=" + access_token;

    var options = {
        method: "POST",
        dataType: "json",
        headers: {
            'Content-Type': 'application/json'
        },
        data: {
            openid: fan_open_id,
            to_groupid: to_group_id
        }
    };

    urllib.request(url, options, function(err, body, resp){

        if(err){
            callback(err);
            return;
        }

        if(body.errcode !== 0){
            callback(body);
            return;
        }

        callback(null);
    });
}
github node-webot / wechat-oauth / lib / oauth.js View on Github external
extend(options, this.defaults);
  if (typeof opts === 'function') {
    callback = opts;
    opts = {};
  }
  for (var key in opts) {
    if (key !== 'headers') {
      options[key] = opts[key];
    } else {
      if (opts.headers) {
        options.headers = options.headers || {};
        extend(options.headers, opts.headers);
      }
    }
  }
  urllib.request(url, options, callback);
};
github cnpm / npminstall / lib / get.js View on Github external
async function _get(url, options, retry, globalOptions) {
  try {
    return await urllib.request(url, options);
  } catch (err) {
    retry--;
    if (retry > 0) {
      const delay = 100 * (MAX_RETRY - retry);
      const logger = globalOptions && globalOptions.console || console;
      logger.warn('[npminstall:get] retry GET %s after %sms, retry left %s, error: %s, status: %s, headers: %j, \nstack: %s',
        url, delay, retry, err, err.status, err.headers, err.stack);
      await utils.sleep(delay);
      return await _get(url, options, retry, globalOptions);
    }

    throw err;
  }
}
github kyfxbl / wechat-toolkit / lib / toolbar_menu.js View on Github external
function queryMenu(access_token, callback){

    var url = "https://api.weixin.qq.com/cgi-bin/menu/get?access_token=" + access_token;

    var options = {
        method: "GET",
        dataType: "json"
    };

    urllib.request(url, options, function(err, body, resp){

        if(err){
            callback(err);
            return;
        }

        if(body.errcode){
            callback(body);
            return;
        }

        callback(null, body);
    });
}
github cnpm / nodeinstall / lib / request.js View on Github external
function* _request(url, options, retry) {
  try {
    return yield urllib.request(url, options);
  } catch (e) {
    if (retry > 0) {
      retry--;
      return yield _request(url, options, retry);
    }
    throw e;
  }
}

urllib

Help in opening URLs (mostly HTTP) in a complex world — basic and digest authentication, redirections, cookies and more. Base undici fetch API.

MIT
Latest version published 12 days ago

Package Health Score

86 / 100
Full package analysis