我正在python上学习udacity课程,我们应该检查文档中的亵渎词.我正在使用网站http://www.wdylike.appspot.com/?q=(text_to_be_checked_for_profanity).要检查的文本可以作为上述URL中的查询字符串传递,并且在检查亵渎词后网站将返回true或false.以下是我的代码.
import urllib.request
# Read the content from a document
def read_content():
quotes = open("movie_quotes.txt")
content = quotes.read()
quotes.close()
check_profanity(content)
def check_profanity(text_to_read):
connection = urllib.request.urlopen("http://www.wdylike.appspot.com/?q="+text_to_read)
result = connection.read()
print(result)
connection.close
read_content()
Run Code Online (Sandbox Code Playgroud)
它给了我以下错误
回溯(最近一次调用最后一次):文件"/Users/Vrushita/Desktop/Rishit/profanity_check.py",第21行,在read_content()文件"/Users/Vrushita/Desktop/Rishit/profanity_check.py",第11行,在read_content check_profanity(content)文件"/Users/Vrushita/Desktop/Rishit/profanity_check.py",第16行,在check_profanity connection = urllib.request.urlopen(" http://www.wdylike.appspot.com/?q" = "+ text_to_read"文件"/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/urllib/request.py",第163行,在urlopen中返回opener.open(url,data,timeout)文件"/ Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/urllib/request.py",第472行,打开响应= meth(req,response)文件"/Library/Frameworks/Python.framework /Versions/3.5/lib/python3.5/urllib/request.py",第582行,http_response'htt',请求,响应,代码,消息,hdrs)文件"/Library/Frameworks/Python.framework/Versions/ 3.5/lib/python3.5/urllib/request.py",第510行,错误返回self._call_chain(*args)文件"/ Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/urllib/request.py",第444行,在_call_chain result = func(*args)文件"/Library/Frameworks/Python.framework/Versions/ 3.5/lib/python3.5/urllib/request.py",第590行,http_error_default引发HTTPError(req.full_url,代码,msg,hdrs,fp)urllib.error.HTTPError:HTTP错误400:错误请求
我试图读取内容的文档包含一个字符串" Hello world "但是,如果我将字符串更改为" Hello + world ",则相同的代码将起作用并返回所需的结果.有人可以解释为什么会发生这种情况以及解决方法是什么?
我正在使用Spring启动学习RESTful Web服务.我正在尝试创建一个获取特定客户端地址的Web服务.但是,当我尝试运行该服务时,我不断收到以下错误:
白标错误页面
此应用程序没有/ error的显式映射,因此您将此视为回退.
Sun Jan 03 11:20:44 CST 2016出现意外错误(type = Not Found,status = 404).没有可用的消息
我想要访问的URL是
有人可以告诉我哪里出错了.我从朋友的github帐户下载了一个类似的项目,它运行得很好.为了简单起见,我尝试对值进行硬编码,并在我的控制器类中创建以下代码:
package com.digitek.controller;
import java.math.BigInteger;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import com.example.model.Address;
@RestController
public class Controller {
private static BigInteger id;
private static Map<BigInteger, Address> addressMap;
//saves address objects into HashMap
private static void SaveAddress(Address address){
//instantiate hashmap when id is null
if(id == null){
id = BigInteger.ONE;
addressMap …Run Code Online (Sandbox Code Playgroud) 我试图通过从用户获取10个数字并将它们添加到数组来进行练习应用程序.这是我的代码
public static void getNumber(){
for(int i=0; i<10; i++){
Scanner scanner = new Scanner(System.in);
System.out.println("Enter number " + i );
int NumbersArray[] = {};
int no1 = scanner.nextInt();
NumbersArray[i] = no1;
System.out.println(NumbersArray);
}
Run Code Online (Sandbox Code Playgroud)
问题是,在接受第一个值后,它会给出一条错误消息
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0
at Number.getNumber(Number.java:17)
at Number.main(Number.java:8)
Run Code Online (Sandbox Code Playgroud)
根据我的格式,第8行是
getNumber();
Run Code Online (Sandbox Code Playgroud)
根据我的格式,第17行是
NumbersArray[i] = no1;
Run Code Online (Sandbox Code Playgroud)
请帮忙