小编Dev*_*ami的帖子

由于 URLLIB,AWS lambda 抛出导入错误

我在 aws lambda 上运行 python 脚本,并抛出以下错误。

 {
   "errorMessage": "Unable to import module 'app': urllib3 v2.0 only supports OpenSSL 1.1.1+, currently the 'ssl' module is compiled with OpenSSL 1.0.2k-fips  26 Jan 2017. See: https://github.com/urllib3/urllib3/issues/2168",
   "errorType": "Runtime.ImportModuleError",
   "stackTrace": [] }
Run Code Online (Sandbox Code Playgroud)

一小时前它运行得很好,即使我没有进行任何部署,它似乎也失败了。

我的Python版本是3.7。我只使用 urllib 来解析和取消引用 urls 。即

from urllib.parse import urlparse

Run Code Online (Sandbox Code Playgroud)

from urllib.parse import unquote

Run Code Online (Sandbox Code Playgroud)

就像 GitHub url 中提到的那样,我可以升级我的 python 版本,但这样做会破坏其他东西。我可以使用任何替代库来获得相同的结果吗?

从 GitHub 链接,它显示 urllib 不再支持 OpenSSL<1.1.1,但不知何故,我们的一些更高环境中相同的脚本运行没有问题。

python urllib amazon-web-services

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

Python:字符串转驼峰命名法

这是来自 Codewars 的问题:完成方法/函数,以便将破折号/下划线分隔的单词转换为驼峰式大小写。仅当原始单词大写时,输出中的第一个单词才应大写(称为大驼峰式命名法,也通常称为帕斯卡大小写)。

输入测试用例如下:

test.describe("Testing function to_camel_case")
test.it("Basic tests")
test.assert_equals(to_camel_case(''), '', "An empty string was provided but not returned")
test.assert_equals(to_camel_case("the_stealth_warrior"), "theStealthWarrior", "to_camel_case('the_stealth_warrior') did not return correct value")
test.assert_equals(to_camel_case("The-Stealth-Warrior"), "TheStealthWarrior", "to_camel_case('The-Stealth-Warrior') did not return correct value")
test.assert_equals(to_camel_case("A-B-C"), "ABC", "to_camel_case('A-B-C') did not return correct value")
Run Code Online (Sandbox Code Playgroud)

这是我到目前为止所尝试过的:

def to_camel_case(text):
    str=text
    str=str.replace(' ','')
    for i in str:
        if ( str[i] == '-'):
            str[i]=str.replace('-','')
            str[i+1].toUpperCase()
        elif ( str[i] == '_'):
            str[i]=str.replace('-','')
            str[i+1].toUpperCase()
    return str
Run Code Online (Sandbox Code Playgroud)

它通过了前两个测试,但没有通过主要测试:

 test.assert_equals(to_camel_case("the_stealth_warrior"), "theStealthWarrior", "to_camel_case('the_stealth_warrior') did not return correct value")
    test.assert_equals(to_camel_case("The-Stealth-Warrior"), "TheStealthWarrior", …
Run Code Online (Sandbox Code Playgroud)

python string

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

python aws botocore.response.streamingbody 到 json

我正在使用 boto3 从 S3 访问文件,目标是读取文件并将其转换为 JSON 但问题是所有文件都没有任何文件扩展名(没有 .csv、.json 等),尽管文件中的数据结构类似于 JSON

client = boto3.client(
    's3',
    aws_access_key_id = 'AKEY',
    aws_secret_access_key = 'ASAKEY',
    region_name = 'us-east-1'
)
obj = client.get_object(
    Bucket = 'bucketname',
    Key = '*filename without extension*'
)
Run Code Online (Sandbox Code Playgroud)

obj['Body']返回一个<botocore.response.StreamingBody>对象

能查出里面的数据吗?

amazon-s3 amazon-web-services python-3.x boto3

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

Pandas 将整数零和一转换为布尔值

我有一个数据帧,其中包含一个由 0 和 1 组成的热编码列,其类型为 dtype int32

a     b      h1      h2     h3
xy    za      0       0      1
ab    cd      1       0      0
pq    rs      0       1      0  
Run Code Online (Sandbox Code Playgroud)

我想将 h1、h2 和 h3 列转换为布尔值,所以这就是我所做的..

df[df.columns[2:]].astype(bool)
Run Code Online (Sandbox Code Playgroud)

但这将 h1-h3 的所有值更改为TRUE

我也尝试过

df[df.columns[2:]].map({0:False, 1:True})
Run Code Online (Sandbox Code Playgroud)

但这也不起作用。(属性错误:“DataFrame”对象没有属性“map”)

int32将数据帧的特定列从0 和 1 转换为布尔值 ( True/ )的最佳方法是什么False

python pandas

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

Github GraphQL API 获取特定日期的问题计数

我正在使用 GitHub Graphql API 来提取存储库的问题。查询如下所示:

query { 
  repository(owner:"OWNER", name:"REPOSITORYNAME") { 
    issues(states:OPEN) {
      totalCount
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

响应有效负载包含存储库的未解决问题的计数。

{
  "data": {
    "repository": {
      "issues": {
        "totalCount": 375
      }
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

搜索文档但找不到任何相关内容,有没有办法我们可以查询历史日期中未解决的问题的数量?例如,totalCount2020 年 10 月 12 日存储库的未解决问题是什么?

github-api graphql

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

配置 microsoft 团队传入的 webhook json 有效负载

我正在尝试使用连接器设置到 Microsoft 团队频道的传入 Webhook incoming webhook。我尝试从平台发送的有效负载如下所示,形式为 CleverTap(失败,因此我尝试使用邮递员对其进行调试)。但我收到错误Summary or Text is required.

{
  "profiles": [
    {
      "email": "jack@gmail.com",
      "identity": "foo",
      "objectId": "-g55b74fb1030740e4a4931910a8abb862",
      "profileData": {
        "Last Score": 308,
        "High Score": 308,
        "Replayed": true
      },
      "name": "Jack"
    }
  ]
}
Run Code Online (Sandbox Code Playgroud)
  1. 我究竟做错了什么?
  2. 我是否需要根据自适应卡语法更改 JSON 有效负载,以便团队接受传入的 Webhook?如果是这样,我可以在自适应卡 JSON 正文中的哪里添加自定义负载?
  3. webhook 端点是否还有其他身份验证因素(我是否必须将发送 POST 消息的 IP 地址列入白名单)?

https json office365 postman microsoft-teams

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