小编Irf*_*fan的帖子

TypeError:ObjectId('')不是JSON可序列化的

我在使用Python查询文档上的聚合函数后从MongoDB返回的响应,它返回有效的响应,我可以打印它但不能返回它.

错误:

TypeError: ObjectId('51948e86c25f4b1d1c0d303c') is not JSON serializable
Run Code Online (Sandbox Code Playgroud)

打印:

{'result': [{'_id': ObjectId('51948e86c25f4b1d1c0d303c'), 'api_calls_with_key': 4, 'api_calls_per_day': 0.375, 'api_calls_total': 6, 'api_calls_without_key': 2}], 'ok': 1.0}
Run Code Online (Sandbox Code Playgroud)

但是当我试图返回时:

TypeError: ObjectId('51948e86c25f4b1d1c0d303c') is not JSON serializable
Run Code Online (Sandbox Code Playgroud)

它是RESTfull调用:

@appv1.route('/v1/analytics')
def get_api_analytics():
    # get handle to collections in MongoDB
    statistics = sldb.statistics

    objectid = ObjectId("51948e86c25f4b1d1c0d303c")

    analytics = statistics.aggregate([
    {'$match': {'owner': objectid}},
    {'$project': {'owner': "$owner",
    'api_calls_with_key': {'$cond': [{'$eq': ["$apikey", None]}, 0, 1]},
    'api_calls_without_key': {'$cond': [{'$ne': ["$apikey", None]}, 0, 1]}
    }},
    {'$group': {'_id': "$owner",
    'api_calls_with_key': {'$sum': "$api_calls_with_key"},
    'api_calls_without_key': {'$sum': "$api_calls_without_key"}
    }}, …
Run Code Online (Sandbox Code Playgroud)

python json mongodb flask

93
推荐指数
11
解决办法
8万
查看次数

Github Push上的权限被拒绝错误

最近,我被添加为Github项目的成员/贡献者.我已经在本地机器上克隆了该项目.

我已经做了一些更改并在本地提交,现在尝试将更改推送到原始仓库但是当我尝试推送时,我得到一些权限错误?

C:\Users\MM\Documents\GitHub\software-licensing-php [master]> git push
origin master
remote: Permission to EasySoftwareLicensing/software-licensing-php.git denied to
 irfandayan.
fatal: unable to access 'https://github.com/EasySoftwareLicensing/software-licen
sing-php.git/': The requested URL returned error: 403
C:\Users\MM\Documents\GitHub\software-licensing-php [master]> git statu
s
# On branch master
# Your branch is ahead of 'origin/master' by 2 commits.
#   (use "git push" to publish your local commits)
#
nothing to commit, working directory clean
Run Code Online (Sandbox Code Playgroud)

我是否缺乏推动变更的许可,所以我可以问项目的原作者?

git github

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

SVN升级工作副本 - TortoiseSVN

我将TortoiseSVN客户端升级到1.8版,并对存储库进行了新的检查.

我在文件中做了一些更改,现在尝试通过右键单击项目文件夹来提交,但我无法做到.它在上下文菜单中显示"SVN升级工作副本",当我尝试从那里升级时,它不起作用并一直问我?我无法提交更改.

知道如何升级本地存储库吗?或者它与服务器SVN版本有关?

svn tortoisesvn

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

该脚本尝试执行方法或访问不完整对象的属性

我收到一个错误,完整的错误是:

Fatal error: authnet_cart_process() [<a href='function.authnet-cart-process'>function.authnet-cart-process</a>]: The script tried to execute a method or access a property of an incomplete object. Please ensure that the class definition &quot;AuthnetCart&quot; of the object you are trying to operate on was loaded _before_ unserialize() gets called or provide a __autoload() function to load the class definition in /home/golfetc/public_html/wp-content/plugins/sccp-2.4.0/authnet_functions.php on line 1266
Run Code Online (Sandbox Code Playgroud)

我正在使用会话来存储购物车对象,并在稍后的某个时候获取它.authnetCart基本上是cart对象的类.

// Check cart in session
    if(isset($_SESSION['AUTHNET_CART'])) {
        // Get cart from session
        $authnetCart = $_SESSION['AUTHNET_CART'];
        foreach($authnetCart->getCartItems() as $item) {  // Line#1266 …
Run Code Online (Sandbox Code Playgroud)

php wordpress session session-variables

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

导入CSV以更新表中的行

大约有26K产品(帖子),每个产品都有这样的元数值:

在此输入图像描述

post_id列是db中的产品ID,_sku(meta_key)是每个产品的唯一ID.

我收到了一个新的CSV文件,用于更新每个产品的_sale_price(meta_key)的所有值(meta_value).CSV文件如下所示:
SKU,销售价格

如何导入此CSV以仅根据post_id(产品ID)和_sku值更新_sale_price行?

输出示例:

在此输入图像描述

我知道如何通过循环CSV并为每个产品选择并执行更新来在PHP中执行此操作,但这似乎效率低下.

最好使用phpMyAdmin并使用LOAD DATA INFILE.

mysql csv import phpmyadmin

20
推荐指数
3
解决办法
4万
查看次数

WooCommerce-如何从网址中删除产品和产品类别?

我在WordPress上使用WooCommerce,它将产品和产品类别添加到URL. http://dev.unwaveringmedia.com/8dim/product-category/all-party-supplies/ http://dev.unwaveringmedia.com/8dim/product/14-snowman-serving-tray/

我需要从网址中删除"产品"和"产品类别".有没有办法修改永久链接并删除它们?

php wordpress wordpress-plugin woocommerce

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

将元素移动到数组的末尾

我有一个包含pagrank值列表的数组.考虑下面的数组:

Array
(
    [0] => stdClass Object
        (
            [pagerank] => 3
        )

    [1] => stdClass Object
        (
            [pagerank] => 1
        )

    [2] => stdClass Object
        (
            [pagerank] => R
        )

    [3] => stdClass Object
        (
            [pagerank] => 2
        )

    [4] => stdClass Object
        (
            [pagerank] => 7
        )

)
Run Code Online (Sandbox Code Playgroud)

我想用'R'来移动/移动页面排名,如:

[2] => stdClass Object
        (
            [pagerank] => R
        )
Run Code Online (Sandbox Code Playgroud)

到数组的末尾,它应该在数组的最后一个索引?

编辑:数组键未知.

php arrays sorting

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

在 PHP 中同时调用多个 API

我正在处理搜索页面。

此搜索页面必须同时为以下 5 个搜索引擎进行 API 调用:

  1. http://www.kijiji.ca/
  2. http://www.lespac.com/
  3. http://www.autonet.ca/
  4. http://www.autotrader.ca/
  5. http://www.carpages.ca/

这个想法是从所有 5 个 API 调用中收集数据,并将其存储并呈现给用户以获取匹配的数据。

让我举一个搜索引擎 API 调用的例子,比如说“KIJIJI”。

示例网址: http://www.kijiji.ca/b-autos-camions/grand-{CITY}/autre+type+de+carrosserie__berline__bicorps__cabriolet__coupe__familiale-{MAKE}-{MODEL}-{MIN YEAR}__/c174l80002a138a54a1000054a68?price=__{Max Price}&kilometres=__{MAX KM}

令牌 {CITY}、{MAKE} 等将替换为用户输入的搜索值。

具有真实价值的搜索网址:

http://www.kijiji.ca/b-autos-camions/grand-montreal/autre+type+de+carrosserie__berline__bicorps__cabriolet__coupe__familiale-Honda-Accord-2010__/c174l80002a138a54a1000054a68?price=__5000&kilometres=__13000
Run Code Online (Sandbox Code Playgroud)

页面提取器网址:

https://api.import.io/store/data/7ddb89d9-1dba-464f-a8e1-d522b50e8c4c/_query?input/webpage/url=http://www.kijiji.ca/b-autos-camions/grand-montreal/autre+type+de+carrosserie__berline__bicorps__cabriolet__coupe__familiale-Honda-Accord-2010__/c174l80002a138a54a1000054a68?price=__5000&kilometres=__13000&_user=8df097bf-2f5d-4509-b13e-299d05bad826&_apikey=H76otVMlVTG2KIW9fCZjWPtf4KzWFmlNBzbD2WIy9qOKSwIPgGxmUFVmTV9dDrORwcTtMBS1zZVLXSdEd9yfPQ%3D%3D
Run Code Online (Sandbox Code Playgroud)

基本上,搜索 URL 进入页面提取器 URL 以获取所有找到的结果的列表。api 调用将大量 url 返回到页面。

个人结果提取器:

https://api.import.io/store/data/e51c6ba5-fbf0-4614-b6a1-4d522b6b6ecf/_query?input/webpage/url=http://www.kijiji.ca/v-autos-camions/laval-rive-nord/2013-honda-accord-sport-sedan/1062203732?siteLocale=en_CA&_user=8df097bf-2f5d-4509-b13e-299d05bad826&_apikey=H76otVMlVTG2KIW9fCZjWPtf4KzWFmlNBzbD2WIy9qOKSwIPgGxmUFVmTV9dDrORwcTtMBS1zZVLXSdEd9yfPQ%3D%3D
Run Code Online (Sandbox Code Playgroud)

第二个 api 调用返回每个单独 URL 的信息。

您可以通过将示例、页面提取器和单个结果提取器复制并粘贴到浏览器中来进行实时测试。do返回json结果。

现在的事情是我必须为单个搜索查询调用上述所有 5 个搜索引擎。我有每个搜索引擎的 api url。

也请看看下面的图片。

在此处输入图片说明

如何通过为单个搜索查询调用多个 api 调用来实现这一点?它是否涉及多线程?

php api multithreading web-scraping

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

为什么我们需要function_exists?

为什么我们需要检查 function_exists 是否存在用户定义的函数?对于内部或核心 PHP 函数来说,看起来没问题,但如果用户知道并自己定义了一个函数,那么为什么需要检查它是否存在呢?

以下是自定义用户定义的函数

if( !function_exists( 'bia_register_menu' ) ) {
    function bia_register_menu() {
        register_nav_menu('primary-menu', __('Primary Menu'));
    }
    add_action('init', 'bia_register_menu');
}
Run Code Online (Sandbox Code Playgroud)

谢谢

php wordpress

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

将HTML表行转换为PHP数组并将其保存到数据库中?

我正在尝试将html表行保存到php数组中,然后将数组保存在数据库中.

<form action="" method="post">
        <table class="widefat" id="theTable">
                        <thead>
                                <tr>
                                   <th>Level Identifier</th>
                                    <th>Non-logged in message</th>
                                    <th>Logged in message</th>
                                </tr>
                        </thead>
                        <tbody>

                                  <tr>
                                    <td><input type="text" value="" style="height: 19px;background-color: white;font-size:10px;"/></td>
                                    <td><textarea style="font-size:10px;" name="promo_msg_free" cols="43" rows="1">This is your custom message template</textarea></td>
                                    <td><textarea style="font-size:10px;" name="promo_msg_free" cols="43" rows="1">This is your custom message template</textarea></td>
                                  </tr>

                                   <tr>
                                    <td><input type="text" value="" style="height: 19px;background-color: white;font-size:10px;"/></td>
                                    <td><textarea style="font-size:10px;" name="promo_msg_free" cols="43" rows="1"></textarea></td>
                                    <td><textarea style="font-size:10px;" name="promo_msg_free" cols="43" rows="1"></textarea></td>
                                  </tr>

                        </tbody>    
                    </table> 
                </form>
Run Code Online (Sandbox Code Playgroud)

我如何检索每个行数据并将其保存到数组元素,最后我将数组保存到数据库?谢谢

html php html-parsing php-parser

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