小编dix*_*hom的帖子

在 AWS Lambda 上使用层时“无法从 'urllib3.util.ssl_' 导入名称 'DEFAULT_CIPHERS'”

我想要实现什么

使用 AWS Lambda 抓取网站并将数据保存在 S3 上。

我遇到的问题

当我执行 Lambda 时,出现以下错误消息。

{“errorMessage”:“无法导入模块“lambda_function”:无法从“urllib3.util.ssl_”(/opt/python/urllib3/util/ssl_.py)导入名称“DEFAULT_CIPHERS””,“errorType”:“运行时.ImportModuleError", "requestId": "fb66bea9-cbad-4bd3-bd4d-6125454e21be", "stackTrace": [] }

代码

最小 Lambda 代码如下。

import requests
import boto3 

def lambda_handler(event, context):
    s3 = boto3.client('s3')
    upload_res = s3.put_object(Bucket='horserace-dx', Key='/raw/a.html', Body='testtext')
    
    return event
Run Code Online (Sandbox Code Playgroud)

Lambda 上添加了一层。使用以下命令将文件保存在python文件夹中,冻结在 zip 文件中,然后作为层上传到 AWS Lambda。

!pip install requests -t ./python --no-user
!pip install pandas -t ./python --no-user
!pip install beautifulsoup4 -t ./python --no-user
Run Code Online (Sandbox Code Playgroud)
  • horserace-dx已存在
  • 该文件夹raw存在
  • Lambda 的角色已正确设置。它可以读取和写入S3
  • Lambda 的运行时是 Python 3.9。本地计算机的python版本是3.9.13。

到目前为止我做了什么

我搜索“无法从‘urllib3.util.ssl_’导入名称‘DEFAULT_CIPHERS’”并找到了一些建议。我用以下代码制作了图层,然后再次尝试,但没有成功。

!pip install …
Run Code Online (Sandbox Code Playgroud)

python amazon-s3 amazon-web-services boto3 aws-lambda

56
推荐指数
6
解决办法
7万
查看次数

Jekyll远程主题在本地不起作用

抽象

  • 我想在Jekyll使用的本地机器中看到一个页面 gem "jekyll-remote-theme"
  • 所以我跑了 bundle exec jekyll serve
  • 但是出现了一个空白页面

我想要实现的目标

  • 要查看Jekyll使用的本地计算机中的页面gem "jekyll-remote-theme".

我正在尝试使用Jekyll和Minimal Mistakes在GitHub页面中构建一个博客.在我推动更改之前,我想检查页面是否一切正常.

环境

  • Windows 8.1 64位
  • ruby 2.4.3p205(2017-12-14修订版61247)[x64-mingw32]
  • 杰基尔3.6.2

我做了什么

  1. bundle exec jekyll new . --force
  2. 使用GitHub Pages方法安装主题
  3. bundle exec jekyll serve

实际发生了什么

我有一个与之相关的错误libcurl.dll.以下是Powershell上的消息.

依赖性错误:哎呀!看起来您没有安装jekyll-remote-theme或其依赖项.为了使用当前配置的Jekyll,您需要安装此gem.来自Ruby的完整错误消息是:'无法打开库'libcurl':(非法字符).无法打开libr ary'libcurl.dll':(非法字符).无法打开库'lib curl.so.4':(非法字符).无法打开库'libcurl.so .4.dll':(非法字符)'如果遇到麻烦,可以在https://jekyllrb.com/help/找到有用的资源!

我按照GitHub页面依赖关系中的说明缺失·问题#17·benbalter/jekyll-remote-theme,问题解决了.

然后出现了另一个错误bundle exec jekyll serve.本地创建的页面为空白.http://127.0.0.1:4000/什么也没说.

PS E:\workspace\mysite\dixhom.github.io> bundle exec jekyll serve
Configuration file: E:/workspace/mysite/dixhom.github.io/_config.yml
            Source: E:/workspace/mysite/dixhom.github.io
       Destination: E:/workspace/mysite/dixhom.github.io/_site
 Incremental build: disabled. Enable with --incremental
      Generating... …
Run Code Online (Sandbox Code Playgroud)

ruby windows github jekyll github-pages

9
推荐指数
1
解决办法
1252
查看次数

在update-core之后的MSYS2中找不到一些主要命令

问题

以后在MSYS2中找不到一些主要命令update-core.

环境

  • Windows 8.1 64位
  • msys2-x86_64-20150916

详情

我将MSYS2引入了我的计算机并执行了update-core.但是,更新后,当我键入pacmanupdate-core,终端说bash: pacman: command not found.我重新启动了MSYS2并尝试了相同的过程,但结果是一样的.我重新安装了MSYS2并尝试了相同的过程,但结果是一样的.我想把事情做对,但不知道怎么做.

任何建议将不胜感激.谢谢.

windows bash msys2

6
推荐指数
1
解决办法
6135
查看次数

如何通过Python抓取动态网页

[我正在尝试做什么]

在下面的网页上搜索二手车数据.
http://www.goo-net.com/php/search/summary.php?price_range=&pref_c=08,09,10,11,12,13,14&easysearch_flg=1

[问题]

刮掉整个页面.在上面的网址中,只显示了前30个项目.这些可能会被我写的下面的代码所刮掉.其他页面的链接显示为1 2 3 ...但链接地址似乎是在Javascript中.我搜索了有用的信息,但找不到任何信息.

from bs4 import BeautifulSoup
import urllib.request

html = urllib.request.urlopen("http://www.goo-net.com/php/search/summary.php?price_range=&pref_c=08,09,10,11,12,13,14&easysearch_flg=1")

soup = BeautifulSoup(html, "lxml")
total_cars = soup.find(class_="change change_01").find('em').string
tmp = soup.find(class_="change change_01").find_all('span')
car_start, car_end = tmp[0].string, tmp[1].string

# get urls to car detail pages
car_urls = []
heading_inners = soup.find_all(class_="heading_inner")
for heading_inner in heading_inners:
    href = heading_inner.find('h4').find('a').get('href')
    car_urls.append('http://www.goo-net.com' + href)

for url in car_urls:
    html = urllib.request.urlopen(url)
    soup = BeautifulSoup(html, "lxml")
    #title
    print(soup.find(class_='hdBlockTop').find('p', class_='tit').string)
    #price of car itself
    print(soup.find(class_='price1').string)
    #price of car including …
Run Code Online (Sandbox Code Playgroud)

html python beautifulsoup web-scraping scrape

5
推荐指数
1
解决办法
2068
查看次数

Progress <T>与Action <T>有何不同?(C#)

我一直在使用Progress<T>,想知道是否可以将其替换Action<T>

在下面的代码中,使用它们中的每个来报告进度(即ReportWithProgress()或)ReportWithAction()对我没有任何明显的影响。如何progressBar1增加字符串,如何将字符串写入输出窗口,它们看起来是相同的。

// WinForm application with progressBar1

private void HeavyIO()
{
    Thread.Sleep(20); // assume heavy IO
}

private async Task ReportWithProgress()
{
    IProgress<int> p = new Progress<int>(i => progressBar1.Value = i);

    for (int i = 0; i <= 100; i++)
    {
        await Task.Run(() => HeavyIO()); 
        Console.WriteLine("Progress : " + i);
        p.Report(i);
    }
}

private async Task ReportWithAction()
{
    var a = new Action<int>(i => progressBar1.Value = i);

    for (int i …
Run Code Online (Sandbox Code Playgroud)

c# generics delegates progress

5
推荐指数
2
解决办法
567
查看次数

将h:m:s和m:s字符串转换为TimeSpan对象的简单方法是什么?

我正在尝试将时间戳字符串转换为TimeSpan对象.但是,TimeSpan.Parse()不能像我期望的那样工作.我会解释原因.

我想转换两种类型的时间戳.

  1. 分:秒
    例如30:53,1:23,0:05
  2. 小时:分钟:秒
    例如1:30:53,2:1:23,0:0:3

问题是,类型1在TimeSpan.Parse()方法中被解释为小时:分钟格式.

Console.WriteLine(TimeSpan.Parse("12:43"));
// the result I expect -> 0:12:43
// the actual result -> 12:43:00
Run Code Online (Sandbox Code Playgroud)

我搜索了这个问题并发现了这个SO帖子.
将HH.mm格式的字符串解析为TimeSpan

这用于DateTime.ParseExact()以特定格式解析字符串.但是,问题是我需要为类型1和2使用不同的格式.

// ok
var ts1 = DateTime.ParseExact("7:33", "m:s", CultureInfo.InvariantCulture).TimeOfDay;
// throws an exception
var ts2 = DateTime.ParseExact("1:7:33", "m:s", CultureInfo.InvariantCulture).TimeOfDay;
// throws an exception
var ts3 = DateTime.ParseExact("7:33", "h:m:s", CultureInfo.InvariantCulture).TimeOfDay;
// ok
var ts4 = DateTime.ParseExact("1:7:33", "h:m:s", CultureInfo.InvariantCulture).TimeOfDay;
Run Code Online (Sandbox Code Playgroud)

我也查了MSDN,但没用.
https://msdn.microsoft.com/ja-jp/library/se73z7b9(v=vs.110).aspx …

c# datetime

3
推荐指数
1
解决办法
171
查看次数

pip install - PermissionError:[Errno 13]权限被拒绝

环境

  • Windows 8.1
  • Python 3.5
  • 蟒蛇

问题

当我这样做时pip install sklearn --upgrade,我收到以下错误:

Exception:
Traceback (most recent call last):
  File "d:\anaconda3\lib\site-packages\pip\basecommand.py", line 209, in main
    status = self.run(options, args)
  File "d:\anaconda3\lib\site-packages\pip\commands\install.py", line 317, in run
    prefix=options.prefix_path,
  File "d:\anaconda3\lib\site-packages\pip\req\req_set.py", line 732, in install
    **kwargs
  File "d:\anaconda3\lib\site-packages\pip\req\req_install.py", line 835, in install
    self.move_wheel_files(self.source_dir, root=root, prefix=prefix)
  File "d:\anaconda3\lib\site-packages\pip\req\req_install.py", line 1030, in move_wheel_files
    isolated=self.isolated,
  File "d:\anaconda3\lib\site-packages\pip\wheel.py", line 344, in move_wheel_files
    clobber(source, lib_dir, True)
  File "d:\anaconda3\lib\site-packages\pip\wheel.py", line 322, in clobber
    shutil.copyfile(srcfile, destfile)
  File "d:\anaconda3\lib\shutil.py", line 115, …
Run Code Online (Sandbox Code Playgroud)

python windows permissions pip anaconda

2
推荐指数
1
解决办法
1万
查看次数