小编ac1*_*c11的帖子

org.apache.http.ProtocolException:未指定目标主机

我写了一个简单的httprequest /响应代码,我得到以下错误.我在类路径中引用了httpclient,httpcore,common-codecs和common-logging.我是java的新手,不知道这里发生了什么.请帮我.

码:

import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.HttpResponse;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.Header;
import org.apache.http.HttpHeaders;

public class UnshorteningUrl {

    public static void main(String[] args) throws Exception
    {           
        HttpGet request=null;
        HttpClient client = HttpClientBuilder.create().build();         

        try {
            request = new HttpGet("trib.me/1lBFzSi");
            HttpResponse httpResponse=client.execute(request);

            Header[] headers = httpResponse.getHeaders(HttpHeaders.LOCATION);
           // Preconditions.checkState(headers.length == 1);
            String newUrl = headers[0].getValue();          
            System.out.println("new url" + newUrl);         
        } catch (IllegalArgumentException e) {
            // TODO: handle exception
        }finally {
            if (request != null) {
                request.releaseConnection();
            }           
        }
    }}
Run Code Online (Sandbox Code Playgroud)

错误:

Exception in …
Run Code Online (Sandbox Code Playgroud)

java httpresponse httpclient apache-httpclient-4.x

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

在sklearn中的TfidfVectorizer中向stop_words列表添加单词

我想在TfidfVectorizer中为stop_words添加一些单词.我按照添加单词的解决方案来scikit-learn的CountVectorizer的停止列表.我的停用词列表现在包含"英语"停用词和我指定的停用词.但是仍然TfidfVectorizer不接受我的停用词列表,我仍然可以在我的功能列表中看到这些词.以下是我的代码

from sklearn.feature_extraction import text
my_stop_words = text.ENGLISH_STOP_WORDS.union(my_words)

vectorizer = TfidfVectorizer(analyzer=u'word',max_df=0.95,lowercase=True,stop_words=set(my_stop_words),max_features=15000)
X= vectorizer.fit_transform(text)
Run Code Online (Sandbox Code Playgroud)

我还尝试在TfidfVectorizer中将stop_words设置为stop_words = my_stop_words.但它仍然无效.请帮忙.

python classification stop-words scikit-learn text-classification

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

NLTK数据安装问题

我正在尝试在Mac OSX 10.9上安装NLTK数据.如NLTK 3.0文档中所述,要设置的下载目录是/ usr/share/nltk_data,用于集中安装.但是对于这条路径,我得到错误OSError:[Errno 13] Permission denied:'/ usr/share/nltk_data'

我可以将下载目录设置为/ Users/ananya/nltk_data进行集中安装吗?

我在我的机器上安装了Python 2.7

谢谢,阿纳尼亚

python nltk

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

从 django 管理操作中间页面重定向到更改表单页面

我正在尝试构建一个管理操作“download_selected”,它将下载选定的模型。选择该操作后,我会重定向到中间页面,以便用户可以选择下载格式。当用户选择下载格式并单击“下载”时,就会下载文件。但停留在同一个中间页面上。如何将其重定向回更改表单管理页面?我想要的这个重定向类似于 django“下载所选文件”默认管理操作。谢谢。

这是我的代码。

管理员.py

class SelectDownloadFormatForm(forms.Form):
    DOWNLOAD_TYPE_CHOICES=[('csv','csv'),
                           ('json', 'json'),
                           ('xml','xml')]

    _selected_action = forms.CharField(widget=forms.MultipleHiddenInput)
    download_type = forms.ChoiceField(label=_('Select a Download type'), choices=DOWNLOAD_TYPE_CHOICES, widget=forms.RadioSelect())


def download_selected(self, request, queryset):
    import csv
    from django.http import HttpResponse, HttpResponseRedirect
    import StringIO

    form = None

    if 'download' in request.POST:
        form = self.SelectDownloadFormatForm(request.POST)

        if form.is_valid():
            dtype = form.cleaned_data['download_type']
            print dtype
            response = HttpResponse(content_type='text/csv')
            response['Content-Disposition'] = 'attachment; filename="export.csv"'
            writer = csv.writer(response)
            writer.writerow(['id', 'name', 'qid' ,'label', 'name', 'field'])

            count = 0
            for s in queryset:
                questions_query = ParentModel.objects.filter(parent_form_id = …
Run Code Online (Sandbox Code Playgroud)

django django-admin django-admin-actions

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