为什么 chaquopy 不识别 Request 库?

Why does chaquopy not recognize the Request library?

我尝试使用 Request 库编写我的项目。一切都很好,chaquopy 安装得很好,可以非常快速地运行 OS 等其他库,但甚至找不到 Request 库。有什么问题?

error:

E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.example.imen_yar, PID: 6169
    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.imen_yar/com.example.imen_yar.MainActivity3}: com.chaquo.python.PyException: ModuleNotFoundError: No module named 'requests'
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3449)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3601)
        at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85)
        at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2066)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loop(Looper.java:223)
        at android.app.ActivityThread.main(ActivityThread.java:7656)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
     Caused by: com.chaquo.python.PyException: ModuleNotFoundError: No module named 'requests'
        at <python>.importlib._bootstrap._find_and_load_unlocked(<frozen importlib._bootstrap>:973)
        at <python>.importlib._bootstrap._find_and_load(<frozen importlib._bootstrap>:991)
        at <python>.importlib._bootstrap._gcd_import(<frozen importlib._bootstrap>:1014)
        at <python>.importlib.import_module(__init__.py:127)
        at <python>.chaquopy_java.Java_com_chaquo_python_Python_getModuleNative(chaquopy_java.pyx:155)
        at com.chaquo.python.Python.getModuleNative(Native Method)
        at com.chaquo.python.Python.getModule(Python.java:84)
        at com.example.imen_yar.MainActivity3.onCreate(MainActivity3.java:27)
        at android.app.Activity.performCreate(Activity.java:8000)
        at android.app.Activity.performCreate(Activity.java:7984)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1309)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3422)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3601) 
        at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85) 
        at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135) 
        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2066) 
        at android.os.Handler.dispatchMessage(Handler.java:106) 
        at android.os.Looper.loop(Looper.java:223) 
        at android.app.ActivityThread.main(ActivityThread.java:7656) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947) 

MainActivity代码:

package com.example.imen_yar;

import static com.chaquo.python.Python.getInstance;
import android.annotation.SuppressLint;
import android.os.Bundle;
import android.widget.EditText;
import android.widget.TextView;
import androidx.appcompat.app.AppCompatActivity;
import com.chaquo.python.PyObject;
import com.chaquo.python.Python;
import com.chaquo.python.android.AndroidPlatform;

public class MainActivity3 extends AppCompatActivity {
    @SuppressLint("SetTextI18n")
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.link_check);
        EditText Ed_text = findViewById(R.id.Ed_text);
        TextView text = findViewById(R.id.text);
        if(!Python.isStarted()){
            Python.start(new AndroidPlatform(this));
        }
        PyObject re = getInstance().getModule("requests");
        String address = "https://google.com";
        int address_login = re.callAttr("get", address).toInt();
        String local_address = "";
        int test = 0;
        for(int num = 6; num > 0; num = num - 1){
            char[] address_char = address.toCharArray();
            local_address = local_address + address_char[0] + address_char[1] + address_char[2] + address_char[3] + address_char[4] + address_char[5];
        }
        if(address_login != 200){
            test+=1;
        }
        if(!local_address.equals("https")){
            test+=1;
        }
        if(test == 0){
            text.setText("link is safe");
        }else{
            text.setText("link isn't safe");
        }
    }
}

requests 不是 Python 标准库的一部分,因此您需要按照 here.

的说明将其添加到您的应用中