小编Rüd*_*ger的帖子

Python 导入请求导致 Traceback -“部分初始化的模块‘请求’没有属性‘发布’”

我正在尝试通过 python 触发 http 帖子。该requests模块是通过安装的pip3 install requests- 现在它也说“要求满足”,所以它被安装了。

我正在使用 Python 版本3.8.0

编码:

import requests as r
headers = {'Accept' : 'application/json', 'Content-Type' : 'application/json'}
url = 'http://localhost:8083/push/message'
jsons = {"test"}
r.post(url, json=jsons, headers=headers)
Run Code Online (Sandbox Code Playgroud)

错误:

Traceback (most recent call last):
  File "http.py", line 1, in <module>
    import requests as r
  File "C:\User\name\AppData\Local\Programs\Python\Python38\lib\site-packages\requests\__init__.py", line 43, in <module>
    import urllib3
  File "C:\User\name\AppData\Local\Programs\Python\Python38\lib\site-packages\urllib3\__init__.py", line 7, in <module>
    from .connectionpool import HTTPConnectionPool, HTTPSConnectionPool, connection_from_url
  File "C:\User\name\AppData\Local\Programs\Python\Python38\lib\site-packages\urllib3\connectionpool.py", line 11, in …
Run Code Online (Sandbox Code Playgroud)

python python-requests

7
推荐指数
3
解决办法
9214
查看次数

在NativeScript中执行XHR-Request时出现UICollectionViewFlowLayout异常

我试图通过Xcode 7对给定的API执行POST请求.我的错误是:

UICollectionViewFlowLayout的行为未定义,因为:项高度必须小于UICollectionView的高度减去截面插入顶部和底部值,减去内容插入顶部和底部值.

相关的UICollectionViewFlowLayout实例是<_UIAlertControllerCollectionViewFlowLayout:0x7f99fe411ea0>,它附加到; layer =; contentOffset:{0,0}; contentSize:{0,0}>集合视图布局:<_ UIAlertControllerCollectionViewFlowLayout:0x7f99fe411ea0>.在UICollectionViewFlowLayoutBreakForInvalidSizes上创建一个符号断点,以在调试器中捕获它.

我试图执行的代码:

打字稿:

makeRatingCall(userRating) {
    var score = userRating;
    var film_edition_id = "123456789";
    var computer_name = ConfigurationService.getUserData().user_username;
    var api_key = "key";
    return new Promise( function (resolve, reject) {
        let xhr = new XMLHttpRequest();
        xhr.open("POST", "my-url" + this.formatParams({film_edition_id, score, computer_name, api_key }), true);
        xhr.setRequestHeader("Accept", "application/json");
        xhr.onload = function() {
            if (xhr.readyState === 4 && xhr.status === 200) {
                resolve(JSON.parse(xhr.responseText).err_code);
            } else {
                reject(xhr.responseText);
            }
        }
        xhr.onerror = function( err ) {
            reject ( …
Run Code Online (Sandbox Code Playgroud)

xcode ios typescript nativescript xcode7

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

Java:根据特定属性创建包含两个给定列表中所有非交叉元素的列表的正确方法?

给定两个对象列表,我将能够根据其中一个属性判断哪些项目不在其交叉点中.我们来看下面的例子:

我有一个Foo有两个属性的类:booplaceholder

class Foo {
    private int boo;
    private int placeholder = 1;

    public Foo(int boo) {
        this.boo = boo;
    }

    public int getBoo() {
        return boo;
    }
}
Run Code Online (Sandbox Code Playgroud)

现在我正在创建两个列表(让我们说这是我的输入)

    List<Foo> list1 = new ArrayList<Foo>();
    list1.add(new Foo(1));
    list1.add(new Foo(2));
    list1.add(new Foo(3));

    List<Foo> list2 = new ArrayList<Foo>();
    list2.add(new Foo(0));
    list2.add(new Foo(1));
    list2.add(new Foo(2));
Run Code Online (Sandbox Code Playgroud)

现在我想根据它们的属性说出哪些项目在list1,不在list2list2不存在.所以在上面的例子中我想要一个包含一个和一个的例子.list1booList<Foo> notInIntersectListFoo(0)Foo(3)

    List<Foo> notInIntersectList = new ArrayList<Foo>();
    list1.forEach(li1foo -> {
        boolean inBothLists …
Run Code Online (Sandbox Code Playgroud)

java

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

C# 将 foreach 循环格式化为 Lambda

我开始使用 C# 并获得了以下课程:

using System;
using System.Collections.Generic;

class PrefixMapSum : Dictionary<String, int> {

    public bool insert(String key, int value) {
        return base.TryAdd(key, value);
    } 

    public int sum(String prefix) {
        int sum = 0;

        foreach (String key in base.Keys) {
            if (key.StartsWith(prefix)) {
                sum = sum + base[key];
            }
        }

        return sum;
    }
}
Run Code Online (Sandbox Code Playgroud)

现在我想用 lambda 表达式缩短代码的以下部分:

        foreach (String key in base.Keys) {
            if (key.StartsWith(prefix)) {
                sum = sum + base[key];
            }
        }
Run Code Online (Sandbox Code Playgroud)

我试过:

new List<String>(base.Keys).ForEach(key => key.StartsWith(prefix) ? sum = …
Run Code Online (Sandbox Code Playgroud)

c# linq lambda

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

尝试在应用程序中使用PrimeNG中的p-Dropdown时出错

我想在我的应用程序中使用此PrimeNG-Dropdown。所以我做了什么:

npm i primeng --save
Run Code Online (Sandbox Code Playgroud)

然后DropdownModule,我从中导入了app.module.ts。之后,我在html中包含以下代码:

<p-dropdown [options]="optionList" [(ngModel)]="selectionString" placeholder="Choose one"></p-dropdown>
Run Code Online (Sandbox Code Playgroud)

在运行ng serve和启动时localhost:4200,出现以下错误:

./node_modules/primeng/components/multiselect/multiselect.js找不到模块:错误:无法在'%projectroot%\ node_modules \ primeng \ components \ multiselect'中解析'@ angular / cdk / scrolling'

我还尝试从imports-Array中删除导入,这导致了另一个错误。我究竟做错了什么?我正在使用Angular 7 btw。

删除导入时,出现以下错误:

Can't bind to 'options' since it isn't a known property of 'p-dropdown'.
1. If 'p-dropdown' is an Angular component and it has 'options' input, then verify that it is part of this module.
2. If 'p-dropdown' is a …
Run Code Online (Sandbox Code Playgroud)

primeng angular primeng-dropdowns

3
推荐指数
2
解决办法
7563
查看次数

使"*"和空间大小相同

我正在为刚接触开发的人准备一个小项目.它包含一些HTML内容,他们应该用Javascript制作一些形状,如矩形或三角形.表格应该由"*""绘制".由于我将介绍&nbsp;元素和一些简单的for和if-constructs,我希望它们创建一个如下所示的矩形:

* * * * 
 * * * 
* * * *
 * * * 
* * * *
Run Code Online (Sandbox Code Playgroud)

在不同的大小.

我可以想象一个看起来像这样的代码:

for (j = 0; j < 10; j++) {
  for (i = 1; i <= 20; i++) {
    if (j % 2 == 1) {
      if (i % 2 == 1) {
        document.write("*");
      } else {
        document.write("&nbsp;");
      }
    } else {
      if (i % 2 != 1) {
        document.write("*");
      } else {
        document.write("&nbsp;");
      }
    }
  }
  document.write("<br/>"); …
Run Code Online (Sandbox Code Playgroud)

html javascript css fonts

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

连接多种认证机制 Spring Boot Security

我的应用程序有一个安全配置,它通过LDAP. 这很有效,但现在我想添加另一个AuthenticationProvider对尝试进行身份验证的用户进行更多检查。所以我试图添加一个DbAuthenticationProvider(出于测试目的)总是拒绝访问。因此,当我尝试使用我的域帐户(适用于activeDirectoryLdapAuthenticationProvider)登录时,我无法访问该页面,因为第二个提供程序未通过身份验证。

为了实现这个目标,我使用了以下代码:

@Configuration
@EnableWebSecurity
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {

    @Value("${ad.domain}")
    private String AD_DOMAIN;

    @Value("${ad.url}")
    private String AD_URL;

    @Autowired
    UserRoleComponent userRoleComponent;

    @Autowired
    DbAuthenticationProvider dbAuthenticationProvider;

    private final Logger logger = LoggerFactory.getLogger(WebSecurityConfig.class);

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        this.logger.info("Verify logging level");
        http.authorizeRequests().anyRequest().fullyAuthenticated().and().formLogin()
                .successHandler(new CustomAuthenticationSuccessHandler()).and().httpBasic().and().logout()
                .logoutUrl("/logout").invalidateHttpSession(true).deleteCookies("JSESSIONID");
        http.formLogin().defaultSuccessUrl("/", true);
    }


    @Override
    protected void configure(AuthenticationManagerBuilder auth) throws Exception {
        auth.authenticationProvider(activeDirectoryLdapAuthenticationProvider());
        auth.authenticationProvider(dbAuthenticationProvider);
    }

    @Bean
    public AuthenticationManager authenticationManager() {
        return new ProviderManager(Arrays.asList(activeDirectoryLdapAuthenticationProvider(), dbAuthenticationProvider));
    }

    @Bean
    public …
Run Code Online (Sandbox Code Playgroud)

authentication spring spring-security spring-boot

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

如何更新 NativeScript Android 的应用程序图标

我有一个已部署到 PlayStore 的应用程序。通过新的更新,我希望这个应用程序显示一个与当前略有不同的图标和启动屏幕。

我的styles.xml

<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:android="http://schemas.android.com/apk/res/android">

    <!-- theme to use FOR launch screen-->
    <style name="LaunchScreenThemeBase" parent="Theme.AppCompat.Light.NoActionBar">
        <item name="toolbarStyle">@style/NativeScriptToolbarStyle</item>

        <item name="colorPrimary">@color/ns_primary</item>
        <item name="colorPrimaryDark">@color/ns_primaryDark</item>
        <item name="colorAccent">@color/ns_accent</item>

        <item name="android:windowBackground">@drawable/splash_screen</item>
        <item name="android:windowNoTitle">true</item>

        <item name="android:windowActionBarOverlay">true</item>
        <item name="android:windowTranslucentStatus">true</item>

        <item name="android:windowFullscreen">true</item>
    </style>

    <style name="LaunchScreenTheme" parent="LaunchScreenThemeBase">
    </style>

    <!-- theme to use AFTER launch screen is loaded-->
    <style name="AppThemeBase" parent="Theme.AppCompat.Light.NoActionBar">
        <item name="toolbarStyle">@style/NativeScriptToolbarStyle</item>

        <item name="colorPrimary">@color/ns_primary</item>
        <item name="colorPrimaryDark">@color/ns_primaryDark</item>
        <item name="colorAccent">@color/ns_accent</item>

        <item name="android:windowFullscreen">false</item>
    </style>

    <style name="AppTheme" parent="AppThemeBase">
    </style>

    <!-- theme for actioon-bar -->
    <style name="NativeScriptToolbarStyleBase" parent="Widget.AppCompat.Toolbar">
        <item …
Run Code Online (Sandbox Code Playgroud)

android nativescript

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

为什么 Lua 库是用 C 代码编写的

我已经开始对 Lua 做一些研究,但我对嵌入式Lua 的工作原理感到非常困惑:

它说

你的程序还需要一个 C 或 C++ 编译器,因为 Lua 头文件和库是用 C 编写的。

所以这意味着,我只需要一个 C/C++ 编译器来执行 Lua,因为库和头文件是用 C 编写的。这意味着我编写和/或使用的所有库都是 C 代码?

我可能误解了这一点,但对我来说这意味着:

我在 Lua 中编写了一些代码,然后在编译之前将其转换为 C 代码?或者我作为库导入和写为“Lua-Code”之间有区别吗?

c lua

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

LuaJIT 能比 C 更快吗?

是否存在 LuaJIT 执行代码的速度甚至比 C 还要快的情况?

经过搜索,我发现有些人在谈论它至少可以与 C 代码相媲美,但我从未见过/找到一个例子,我无法想象如何创建一个 Lua 比 C 更快的设置,因为 Lua 似乎依赖 C 库。

有没有人有过发生这种情况的场景和/或可以向我展示 Lua 比 C 代码更快的示例?

c performance lua

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

我可以在单个子模块中返回先前的提交吗?

我想将我的应用程序设置为一些服务,但所有服务都在一个存储库中.所以我想为每个服务添加一个子模块(我目前只有两个子模块).所以我的项目层次结构是:

- root
|--rootDoc.txt
|--.git
|
|---- sub1
    |--sub1.txt
    |--.git
|---- sub2
    |--sub2.txt
    |--.git
Run Code Online (Sandbox Code Playgroud)

现在我做了以下更改:

  • 更改 sub1.txt
  • commit sub1子模块
  • 推主要掌握
  • 更改 sub2.txt
  • commit sub2子模块
  • 推主要掌握

现在我想将sub1-submodule 返回到最后一次更改之前的状态,但保持sub2其当前状态.如果子模块不可能,那么我的问题是否有另一种解决方案,还是需要使用两个完全不同的存储库?

编辑: 我尝试了什么:

c:\dev\root\sub1>git log
commit a172db9a5f11738383d28e082db2c22d3f2d3e75 (HEAD -> master, origin/master, origin/HEAD)
Author: %me%
Date:   Sun Dec 2 20:24:59 2018 +0100

    updated sub2

commit 0becb718a4db9c73b03fa65e332f20c7715463cb
Author: %me%
Date:   Sun Dec 2 20:23:40 2018 +0100

    sub1 actual now

commit 85d68703bff1af2b95a7ee8d7926d7fd700b1da4
Author: %me%
Date:   Sun Dec 2 20:10:50 2018 +0100 …
Run Code Online (Sandbox Code Playgroud)

git git-submodules

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

在 Angular 7 中使用 PrimeNG 的 flexgrid 没有任何效果

我想使用 PrimeNG 的FlexGrid并尝试简单地复制示例:

<div class="p-grid">
    <div class="p-col">1</div>
    <div class="p-col">2</div>
    <div class="p-col">3</div>
</div>
Run Code Online (Sandbox Code Playgroud)

它应该输出1 2 3彼此相邻的数字。遗憾的是它没有,而只是输出:

1
2
3
Run Code Online (Sandbox Code Playgroud)

我可以使用 PrimeNG 的按钮样式。然而,我确保我导入了入门指南中提到的 css 文件。在我app.module.ts它说:

        "styles": [
          "src/styles.css",
          "node_modules/primeicons/primeicons.css",
          "node_modules/primeng/resources/themes/nova-light/theme.css",
          "node_modules/primeng/resources/primeng.min.css"
        ],
Run Code Online (Sandbox Code Playgroud)

所以这些似乎在那里。我做错了什么?

css primeng angular

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